监测目录的内容变化 [英] Monitor directory content change
本文介绍了监测目录的内容变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在写一个bash脚本,我想监控文件的更改到一个目录(添加,删除和重命名),并据此进行不同的操作。
I'm writing a bash script, and I'd like to monitor file changes into a directory (adding, deleting and renaming) and performing different action accordingly.
有没有办法做到这一点直接从我的脚本(除了周期性 LS
的目录,使差异
S)?
Is there a way to do that directly from my script (aside from periodically ls
the directory and make diff
s)?
推荐答案
您可以使用 inotifywait
命令(假设您的发行支持inotify的,其中大部分做):
You can use the inotifywait
command (assuming your distribution supports inotify, which most do):
inotifywait -m -r --format '%f' -e modify -e move -e create -e delete ~/test | while read line
do
echo "File: $line"
done
这篇关于监测目录的内容变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文