System and processes
The bg command
Resumes a stopped job in the background, so it runs without holding the terminal.
Most useful options
%nJob number, such as %1. It is the one jobs shows in brackets.%n %mSeveral jobs at once: bg %1 %2 resumes both in the background.%% o %+The current job: the last one started in the background, stopped or resumed. It is the one used with no argument.%-The job before the current one.%?textoA job whose command contains that text anywhere, such as %?100.Copy-ready examples
$ jobschecks which jobs are stopped before resuming one.$ bgresumes the current job in the background.$ bg %1resumes job number 1 in the background.$ bg %1 %2resumes jobs 1 and 2 at once.$ kill -STOP %1 && bg %1stops a job already in the background with kill and then resumes it.You can try them in the browser terminal: it does not touch your computer.
Common errors
| Message | Cause | Fix |
|---|---|---|
| bash: bg: current: no such job | There are no jobs in this shell: they finished or were never started. | Run jobs to check, and start the command with & or suspend it with Ctrl+Z. |
| bash: bg: no job control | The shell has job control off, which is typical in a script. | If you need bg in a script, run set -m at the start. |
Typical mistakes
- A stopped job does not advance until you resume it with bg or bring it back with fg.
- bg does not start anything new: it only resumes a job that already existed and was stopped.
- A job resumed in the background that tries to read from the keyboard stops again (SIGTTIN). Bring it back with fg so it can read.
Differences from similar commands
- fg: brings the job to the foreground and gives it your keyboard. bg leaves it running without holding the terminal.
- nohup: starts a new command that ignores SIGHUP. bg starts nothing: it resumes one that already existed and was stopped.
- kill: sends a signal by PID or by %N. With kill -CONT %1 the process runs again, but bg is the command meant for resuming a job.
FAQ
How do I stop a job that is already in the background?
With kill -STOP %N, which suspends it without cancelling it. To resume it in the background, use bg %N.
Does its output keep appearing in my terminal?
By default, yes: a background job can write to the terminal and its output mixes with yours. If you want it separate, redirect it when you start the command with > file 2>&1.
Is it the same as starting it with &?
According to the bash manual, bg resumes it as if it had been started with &. The difference is that the process already existed and keeps what it had done.
Learn to actually use it
The basic Linux course takes you from zero to console fluency with 24 self-grading lessons.
Start the free course