Running a command in the background

There are some situations in which you might want to continue running other commands as you wait for another one to complete, to run more than one job in parallel. You can arrange for a command to run in the background by ending it with a single ampersand (&) control operator.

You can try this out by issuing a sleep command in the background. The sleep built-in Bash command accepts a number of seconds to wait as an argument. If you enter such a command without the &, Bash won't accept further commands until the command exits:

$ sleep 10# Ten seconds pass...
$

However, if you add the & terminator to start the job in the background, the behavior is different: you get a job control number and a process ID, ...

Get Bash Quick Start Guide 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.