regex - 如何使用 stat linux 命令检查文件是否更改

标签 regex linux shell grep openwrt

我想使用 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: 1

Access: (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 +0200

linux@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/

相关文章:

bash - 如何在 shell 脚本中创建别名?

shell - 从命令行更改文件夹权限(在 mac 上)

regex - 如何拆分并保存到数组

linux - 在 Windows 中像 RDP 一样访问 VPS linux 主机

c - 如何打开读/写线颠倒的串口?

linux - 嵌入式Linux能否满足200ms的时序要求?

java - 通过 shell 传递以空格分隔的系统属性

regex - sed : extract multiple fields in random order

Java String.replaceAll 正则表达式

javascript - 在 Node.js 中实现更好的正则表达式的方法