On a unix system, how do I monitor (like how 'tail' works) a directory for changes made to files - either new ones created, or size changes, etc.
Looking for a command line tool rather than something to be installed.
Locate the file or folder whose permission changes you wish to track. Right click on it and go to Properties. In the Security tab, click the Advanced button. In Advanced Security Settings for Active Directory window, go to Auditing tab, and click the Add button to add a new auditing entry.
You can use the ellipsis (...) button to browse for the folder. Select this option to monitor the files and folders in sub-folders in the Folder that you specified.
To test how fswatch works, open two Terminal windows (Let us call them Terminal 1 and Terminal 2). In Terminal 1, run the fswatch command to monitor the $HOME directory.
Most unix variants have an API for this, but it's not standardized. On Linux, there is inotify. On the command line, you can use inotifywait
. Usage example:
inotifywait -m /path/to/dir | while read -r dir event name; do
case $event in
OPEN) echo "The file $name was created or opened (not necessarily for writing)";;
WRITE) echo "The file $name was written to";;
DELETE) echo "The file $name was deleted ";;
esac
done
Inotify event types are often not exactly what you're trying to notice (e.g. OPEN is very wide), so don't feel bad if you end up making your own file checks.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With