Skip to content
Snippets Groups Projects
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
misc.md 4.60 KiB

Miscellaneous Utilities

man

This is one command you need to know. It gives you access to the manual pages ("man pages" or "manpages", for short) for programs. When you don't know what a program does, or what options it has, man program should be the first thing you try.

kill and killall

When a program is out of control, or if it's running in the background, you will probably need to fall back on the kill command to terminate it. This takes one or more process IDs (PIDs) as arguments, and optionally the signal to use. SIGTERM is the default, and is usually what you want, though sometimes you want SIGKILL:

kill 1234     # kill PID 1234 with TERM signal
kill -9 1234  # kill PID 1234 with KILL signal

Note that the TERM signal can be caught by the process being killed, allowing it to clean up after itself. The KILL signal cannot be caught, and causes the process to terminate immediately.

The killall program matches command names, rather than PIDs. It is potentially error-prone, but sometimes very useful.

true and false

These are very useful in scripts. true exits with status 0, and does nothing else. false exits with a non-0 status (often -1), and does nothing else. These can be used as nops, or to create infinite loops:

while true
do
    # ...
done

until false
do
    # ...
done

yes

This program is similar to the file /dev/zero, in that it will keep providing output as long as you read it. Rather than producing nulls, it produces an infinite stream of lines containing the character "y". This can be useful for scripting with tools that require confirmation.

seq

This produces a sequence of numbers, optionally with a starting point and increment. Compare the following:

seq 5
seq 1 5
seq 1 2 5
seq 5 1
seq 5 -2 1

See the manpage for other options, including more complex formatting.

This is useful in scripts to provide a loop over indices:

for a in $(seq 0 5)
do
    # ...
done

tar