E-Mail:
Get our new Windows 7 eBook (PDF) for $7 with 70+ Tips. Download Now!

CLI Magic: Watch it

  • No Related Post

This week we’ll take a look at a very simple command called watch. You know what they say, a watched pot never boils. That’s why it makes good sense to take advantage of this little tool to watch it for you. Waiting for mail? Want to see if a job has completed? Watch can help. At the CLI, of course. Climb down out of your GUI and take a look.

Watch allows you to see a real-time display of the latest output — the first screenful of output — from a command. So instead of you having to retype the command 50 times while you wait for whatever to occur, you tell watch to do it for you. By default, watch reissues your command every 2 seconds.

The basic format for the watch command is simply watch command. Once started, watch keeps running until it is stopped. You don’t want to use watch to programs that keep running. If you do, you’ll be sorry.

For example, you do not want to issue a command like this one: watch xchat. That watch command would start a new copy of xchat running every 2 seconds, and keep on doing that until your system expired from lack of resources. Not a good thing.

Watch is made for commands that output data when executed and then stop. There are a lot of those to choose from: things like who, ls, df, and netstat.

Let’s try netstat as an example, and see what happens when we enter watch ‘netstat -stu’ at the CLI to create an interesting, almost real-time TCP/UDP connections summary monitor:

Complete Article

What Do You Think?

 
35 queries / 0.338 seconds.