inotifywait 命令监控文件被删除的情况

inotifywait 命令监控文件被删除的情况

如果文件被删除,则不会发出通知。它适用于创建的文件。

delete      file or directory deleted within watched directory
dir=/home/andy/Downloads/


inotifywait -m "$dir" --format '%w%f' -e create -e delete |
    while read file; do
        date +'%m/%d/%Y %I:%M:%S %p' >> /home/andy/Downloads/New_Created_Files.txt
        echo New file downloaded OR created. >> /home/andy/Downloads/New_Created_Files.txt
        gxmessage -fg red -font  'sans 25' -timeout 3 ' File has been created,deleted, or moved to the specified directory.'
    done

答案1

dir=/home/andy/Downloads/

inotifywait -m "$dir" --format '%w%f' -e create -e delete -e moved_to -e moved_from |
    while read file; do
        date +'%m/%d/%Y %I:%M:%S %p' >> /home/andy/Downloads/New_Created_Files.txt
        echo New file downloaded OR created. >> /home/andy/Downloads/New_Created_Files.txt
        gxmessage -fg red -font  'sans 25' -timeout 3 ' File has been created,deleted, or moved to/out of the specified directory.'
    done

相关内容