Linux Watch Command Fails on Second Try

I am not a system admin so I don’t remember how to do an infinite loop in bash, tcsh, ksh, perl, wtv*sh etc.  So I really like the solution of the ‘watch‘ command.

Example:

watch du -sh *   # watch the file size of current directory grow
watch `du -sh * | tail -n3`  # watch the size of just the last 3 files

The Problem on Second Try

Sometimes, however, the first try works as desired and the second try prints weird errors, often in weird output that stacks on top of itself. This drove me nuts and I couldn’t find the solution quickly ever and ended up re-running the command manually.

The Solution

Finally today someone saw me struggling and knew with this particular process standard error was written to frequently and suggested putting stderr to dev null in the watch command.

watch "df -h 2>/dev/null"   # watch mount file size grow
watch "df -h 2>/dev/null | grep ess"   # watch ess mounts grow

After looking more into it the double quotes also solves other problems with displaying the output correctly etc. Thank you so much for helping me be just that slightly more productive without having to do things the hard way!
I hope this helps you too.

Post to Twitter Post to Delicious Post to Facebook Post to Reddit

Loading Disqus Comments ...