Continuously monitor a directory in linux and notify when a new file is available
You are looking for something like inotify
.
[cnicutar@ariel ~]$ inotifywait -m -e create ~/somedir/Setting up watches.Watches established./home/cnicutar/somedir/ CREATE somefile
For example, you could do it in a loop:
inotifywait -m -e create ~/somedir/ | while read linedo echo $linedone
inotify
is the perfect solution to your problem. It is available as a system command that can be used in a shell, or as a system call that can be used in a C/C++ program. For details see the accepted answer to this question: Inotify - how to use it? - linux
Update: you need inotify-tools
for use on command line. The answer to the question above only describes C/C++ system calls. Here is the link to inotify-tools. It is also available as a packaged distribution so search your favorite install repository (yum
/apt-get
/rpm
etc.): https://github.com/rvoicilas/inotify-tools/wiki