7

Basically the question is in the title. I want to monitor a directory for new files that are written or deleted, the way I can monitor a log file with tail -f. Is this possible?

2 Answers 2

17

Try watch.

Taken from here:

watch -d ls -l

A friend and I tried this a moment ago, it seems that the highlighting doesn't really work correctly, it will highlight a seemingly random selection. I've tried this in an OS X Terminal ssh'd to a RHEL5 machine and my friend has tried in a Ubuntu GUI terminal.

Unfortunately inotifywait is not present on the RHEL5 machine so I can't give any information on the effectiveness of that command.

3
  • inotifywait is part of inotify-tools. Jun 20, 2012 at 13:27
  • Thanks. Looks like it's probably the preferred solution, especially with a system that you can add binaries to.
    – arpz
    Jun 20, 2012 at 14:58
  • 1
    Put the command in quotes if the commands has one or more pipes. watch -d "ls -l | grep avi".
    – Bibhas
    Sep 18, 2013 at 21:58
6

inotifywait from inotify-tools shows a real-time log of file modifications, similar to tail -f.

inotifywait -m -q -e create,delete,move /dir

-r can be added for recursive watches (can be a little slow with many subdirectories), --format to change the output format (e.g. add timestamps or join the path & filename).

Example output:

/home/grawity/code/bin/ CREATE,ISDIR fallback
/home/grawity/code/bin/ CREATE gnome-inhibit-list
/home/grawity/code/bin/ CREATE k5translate
/home/grawity/code/bin/ MOVED_FROM logout
/home/grawity/code/bin/ DELETE pacman-sigstats

(By the way, tail -f also uses inotify to follow file changes.)

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .