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!

Quick Way to Find PHP’s Temp Folder

If you want to know what folder (in Linux), that PHP is using for temps, you can always check the php.ini. However, the setting for temp folder is often commented out, leaving the “system default” as the folder of choice. But what is that?

One way is to just type “df” at the command line, chances are good you’ll see the symlink path to temp in here. In fact most of the time it’ll just be “/tmp/” anyway. But here is one more trick.

Create a php file and just put this code in it:

    $temp_file = tempnam(sys_get_temp_dir(), 'Tux');
    echo $temp_file;

Run that on your server and it should give you a pathname to the created temp file. You’ll know for sure what PHP is using.