watch – a useful tool

Sunday, August 31st, 2008 | linux

I’ve been doing a lot of testing on a newly commissioned Linux cluster recently. A lot of the work involves running various scripts and ensuring that the correct output is generated (or that some output is generated). All too often, I end up typing

ls -la

repeatedly to check the output of some test script or to see whether anything is getting output. I’ve come across watch before but it had slipped my mind. After rediscovering it the other day, I was again reminded how elegant and powerful the unix philosophy of having simple commands which do one thing well but can be chained together to do very complex things is. The task of monitoring a directory is much simplified with a single

watch ls -la /directory

Not to mention the reduced RSI! If you haven’t used watch before or have simply forgotten about it – you might want to revisit, especially if you’re doing a lot of repetitive commands to view the status of something on your system.

On a related note, we wanted to monitor the timestamps of various output files – and the ls command’s usual hour:minute timestamp information lacked the granularity we needed for our measurements. The man page came to the rescue with the following

ls -la –time-style=full-iso

which gives seconds and even milliseconds (for some files, I suspect it depends on the command creating the files) in the timestamp.

No comments yet.