Today, I Learned...

by Justin Campbell

< All

Unix Background Jobs

You can execute a command in the background by putting an ampersand at the end of the line:

$ sleep 60 &
[1] 10075

See the currently running jobs with jobs:

$ jobs
[1]+  Running                 sleep 60 &

Foreground the most recent job with fg, or foreground that specific job with fg %1:

$ fg %1
sleep 60

You can also pause/stop currently running commands with Ctrl-Z:

[1]+  Stopped                 sleep 60

And then tell that command to continue running in the background with bg:

$ bg
[1]+ sleep 60 &

Learned from @sethvargo and @ivey.

June 10th, 2013