On a UNIX machine, you can run many programs simultaneously.

When you type commands on a UNIX system, you use a UNIX shell. The shell is a program for spawning new commands. Usually, the shell waits for one command to finish before it starts a new one. For example, if you type the cd command and then the ls command, the shell waits for the cd command to complete before it lists the new directory. When you start a mail program on the command line, the shell waits for you to exit the mailer before it gives you another prompt.

However, when running programs that might take a long time and that aren’t interactive (that is, that don’t prompt you for more input in the terminal window) you may put those commands in the background. To put a command in the background, you simply place an ampersand at the end of the command line, like this:

% grep 
 waldo * > grep.waldo &

This command searches through each line of each file in the directory for the text string “waldo” and prints any matching lines into the file grep.waldo. Since the grep command may take a long time to search through all the files in the directory, we put the command in the background so we don’t have to wait for it to finish before we can run other commands in that shell.

When the background process ends, you’ll get a message to your terminal the next time you press Return:

[1] Done grep waldo * > grep.waldo

Now for a word of caution. If you want to grep for many different things in a directory, you may be tempted to start several ...

Get WYNTK: UNIX System Admininistrator now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.