我想使用 stat linux 命令检查文件是否已更改。
linux@server:~/$ stat test.txt File: `test.txt' Size: 23
Blocks: 8 IO Block: 4096 regular file Device: 802h/2050d Inode: 4887765 Links: 1Access: (0644/-rw-r--r--) Uid: ( 1000/ anis) Gid: ( 1000/
anis)Access: 2014-07-07 16:34:42.476315578 +0200
Modify: 2014-07-08 12:54:15.756553868 +0200
Change: 2014-07-08 12:54:15.756553868 +0200
我们可以看到变化的时间。 目的是利用这个更改时间来检查文件是否被修改
linux@server:~/anis$ stat test.txt |grep Change
Change: 2014-07-08 12:54:15.756553868 +0200linux@server:~/anis$ stat test.txt |grep Change
Change: 2014-07-08 15:14:03.107977776 +0200
那么如何让脚本无限循环运行来检查时间是否改变?
最佳答案
不要使用stat
。要简单地阻塞直到文件被修改,请使用 inotifywait
:
inotifywait -e modify test.txt
您可能需要等待一组限制较少的更改:
inotifywait test.txt
将阻塞,直到文件上发生任何事件。另外,请考虑用户的理智:
inotifywait -qq test.txt
关于regex - 如何使用 stat linux 命令检查文件是否更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24633452/