Monitoring files and output
When running programs, one often wants to watch a file that is changing on disk. Many text editors can handle this, but on some systems it can be a bad idea if a file is changing rapidly, or can be irritating to have to keep refreshing.
The simplest way to track a file as it changes is the command
tail -f [filename]
This will show the last few lines of a file and will update as the content changes. The
-n [number] argument to tail changes the number of lines displayed to
Similarly to tail, the
head command, shows the first lines of the file.
less utilities are both pagination commands. They can be passed a filename, or program output can be piped to them. The arrow keys can be used to move around, and the space bar jumps forward and entire page. Just like vim, :q<Enter> quits. A command like
username@machine:~>./my_program | less
lets you scroll through program output more slowly than it is produced.
Finally, the watch command can be used to monitor file output or contents. For example, as given on the man page for watch (1),
watch -d ls -l
will show files as they appear in the current directory.
To see running processes on a system, there is the command top, which shows a live monitor of running processes and their memory use etc.
The command ps shows a list of current processes. It is most useful in combinations like
ps aux | grep [username]
which shows all processes from user [username].