Quick Linux Tip #51:
Try: inotifywait -m -r -e create,modify,delete,move --timefmt '%Y-%m-%d %H:%M:%S' --format '%T %w%f %e' /var/www
Info: inotifywait uses Linux kernel APIs for efficient file monitoring. -m runs continuously, -r recurses through subdirectories, and -e filters the specified events.
Examples:
- $ inotifywait -m -e close_write /uploads | while read path event file; do process.sh "$path$file"; done # Trigger script on write
- $ inotifywait -m --exclude '\.tmp$' /home/linuxteck # Ignore temp files
- $ inotifywatch -v -e access -t 60 /var/log # Collect statistics over 60s
Note: Requires the inotify-tools package (sudo apt install inotify-tools). Kernel events fire instantly with minimal CPU overhead.
Leave a Reply