How to Monitor a Folder for Changes in Linux in Real Time

This is a handy little command I found recently.

I was testing something on my CentOS server and needed to look at a particular folder to wait for a file to appear. I quickly tired of typing ll over and over to see if the folder changed.

After a little web searching I was almost giving up until I found watch. This command simply runs any command you like, at a set interval, and updates the screen each time.

For the purposes of this post, I simply needed to run watch -d ‘ls -l’.

The -d switch tells watch to highlight changes between the previous screen and the new one. This was amazing as it highlighted the very file that I was waiting for to appear.

You can set the time limit with the -n switch but without it the default is 2 second intervals.

As with most commands, read up about it by typing man watch or do some web searching. Watch is limited to showing you one page of data, so it may not be appropriate for commands that spit out a lot of stuff.

Hope that helps!

Your Thoughts Matter!...