Archive for December, 2011

Following status of a file or command

A command most people know about in POSIX systems, is “tail”. A command showing you the ‘tail'(in most cases, the last lines) of a file or pipe. Or with the option -f, it actually monitors your files, and will show the newly appended lines live.

But a command that is not that much known is “watch”. Say someone is uploading a file to your FTP server, and you want to see the file grow in size. If you want to “monitor” how big the file has become without making a “bash loop” that clears the screen and runs the command again, often making a flickering output, you can easily just type:

watch -n 1 du -h uploadedfile.zip

Watch will now every second run the command “du -sh uploadedfile.zip” and display it on your screen, along with the current time.

Or if you want to look at a whole folder being uploaded to:

watch -n 1 ls -lah ~/upload

Would at all times show the latest directory information about your upload folder. Any files growing in size, or any new files appearing would be shown each second. This if of course just a few simple examples of how to use the tool “watch”.