Computer Trivia: Amp Off

šŸ“… January 14, 2015
ampoffHere is a computer term rarely heard these days: amp off.

To amp off means to run in the background, and it is derived from the ampersand character (& or amp) placed at the end of a command line in a Linux or UNIX terminal.

When a command is executed at a command prompt, the shell waits for completion before returning shell control to the user. This can involve lengthy wait times for time-consuming commands and processes, such as searching for a particular text string that could be located in any of thousands of files.

For example,

grep -r "amp off" /

will recursively search for and list all lines and files containing the phrase “amp off” starting from the root directory. This can take a very long time–even with a reasonably fast computer if the hard drive contains a plethora of files. We cannot enter any more commands in the current shell until the process completes. (Press Control + C to abort the process.)

But if we append an ampersand character to the end of the command,

grep -r "amp off" / &

then we can immediately use the shell while the search is performed as a background job. However, entered text will compete with the grep process output in the same terminal unless its output is redirected to a file or another terminal. Let’s see how to redirect grep’s output.

Redirecting Standard Error to a Second Terminal

Suppose there is a second terminal open named /dev/pts/5. (Enter tty within a terminal to find the terminal device. Linux Mint 17.1 is used in this example.) We can redirect standard error from grep to /dev/pts/5 while running grep in the background from the current terminal.

grep -r "amp off" / 2> /dev/pts/5 &


Redirecting grep’s standard error message from the current terminal to a second terminal. Standard grep output will still appear in the current terminal.

The current terminal will show the job number and process ID (PID) of grep once started.

[4] 3769

In this example, [4] is the job number, and 3769 is the PID.

Any errors will appear in the second terminal /dev/pts/5 to avoid cluttering the current terminal.

To list all jobs running in the current shell, enter jobs. To kill a job, type kill %4, but be sure to replace the 4 with the actual job number. It could be 1, 2, 3, or any other number if multiple jobs are running. kill %1 would terminate job number 1. kill 3769 would also work. Replace 3769 with the actual PID since 3769 is only an example.

Redirecting Both Standard Error and Standard Output

If we want to redirect both standard output and standard error to the second terminal, type:

grep -r "amp off" / &> /dev/pts/5 &



Redirecting grep’s error messages and search results to a second terminal. This frees up the current terminal so we can use it while grep is searching in the background. The second terminal allows us to watch what grep is doing.

Remember to replace /dev/pts/5 with the destination terminal, which will probably have a different name from this example.

Avoid Ampersand Confusion

Do not confuse the two ampersands:

grep -r "amp off" / &> /dev/pts/5 &

&> and & mean two different things. &> is a shortcut redirection operator that redirects both standard output (stdout) and standard error (stderr) to /dev/pts/5, and & alone at the end of the command line will amp off or run grep in the background so the user can continue using the shell. An ampersand (&) at the end always means “run this command in the background.

Why Run in the Background?

In the early days of slow computing and full-screen, single-task terminals, the ability to use the shell without waiting for the previous command to complete was a blessing. It eliminated much waiting on a UNIX system.

In these days of sleek GUIs and faster computers that allow multiple virtual terminals, shell-based background jobs and redirection is more suited for command line parlor tricks that impress the uninitiated rather than as an essential piece of computer usage.

But who knows? There are times when we might be limited to a full-screen shell until we can restore the GUI, so it might be worthwhile to know how to amp off a time-consuming command while we perform other tasks.

, ,

  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: