Watch and Screen
I want to mention two very useful commandline tools in Linux and other UNIX based systems. I use these all the time but they are rarely mentioned in Linux guides and documentation. They are screen and watch.
screen allows you to:
- Log out and yet leave a process running.
- Move a terminal from one computer to another without interrupting the running processes.
- Manage several running processes from one terminal.
I mainly use this if I have a large download to do or a big batch processing job to run - anything which takes a few hours. I can start a big download on my home box in the morning and then log in via SSH from work during the day to see how it is going.
Most Linux distros do not install screen by default so you will need to do that (you are running Debian right ?):
# apt-get install screen
Then activate it:
$ screen
Start your big process and then press Ctrl-A D to detach the process from the terminal. To re-attach the process, type:
$ screen -r
You can start as many screens as you like and reattach each individual one by referring to its process id as in this example:
$ screen -r 6255
UPDATE
If you want to attach a screen but forgot to detach it before you left home (oops!), you can force it to detach using the -D option like this:
$ screen -D -r 2324
watch lets you run a command periodically. The most common thing I do with this is monitor disk usage while performing large file transfers (so I know when to panic if the disk is getting too full). To do this, simply type:
$ watch df -h
I usually leave that running in a separate window. A more advanced form of the same thing would be to monitor the disk free space while also listing the size of each file in the current directory:
$ watch "df -h; echo ; ls -l"
I can even do more fancy things like monitor the number of items in a database table:
$ watch psql rego -c "select count(userid) from users"
These commands make the commandline so much more useful. Its a shame more people do not know about them.
