LinuxCommandLibrary

bg

Move a stopped job to background

TLDR

Resume the most recently suspended job and run it in the background

$ bg
copy

Resume a specific job and run it in the background (run jobs to find the job number)
$ bg %[job_number]
copy

SYNOPSIS

bg [jobspec ...]

PARAMETERS

jobspec
    Job identifier such as %+ (current), %- (previous), %n (job number n), or %string (job starting with string). Omitting resumes current job.

DESCRIPTION

The bg command is a shell built-in in POSIX-compliant shells like Bash and Zsh, designed for job control. It resumes suspended jobs (stopped via Ctrl-Z or SIGTSTP) and runs them asynchronously in the background, immediately returning control to the shell.

This allows multitasking in interactive sessions: suspend a long computation or editor, issue other commands, then resume it later without blocking the terminal. Unlike starting a new job with &, bg targets existing suspended jobs listed by jobs.

Without arguments, it affects the current job (most recently suspended, denoted %+). Specify multiple jobspec to resume several at once. Background jobs may still output to the terminal unless redirected; completion notifications appear if the notify shell option is enabled.

Essential for command-line productivity, bg pairs with fg for foreground resumption and jobs for management. It requires an interactive shell with job control active (default in terminals).

CAVEATS

Only resumes suspended (stopped) jobs, not running or foreground ones. Requires job control (interactive shell). Limited to jobs in current shell session; cannot affect subshells or other terminals.

EXAMPLES

sleep 60
^Z (suspends job)
jobs (lists: [1]+ Stopped sleep 60)
bg %1 (resumes in background)

top &
^Z
bg (defaults to current)

JOB CONTROL NOTES

Use set -m to enable job control if disabled. suspend -f prevents accidental suspension. Redirect output: bg; command > log.txt.

HISTORY

Originated in BSD C shell (csh) in the late 1970s for job control. Adopted in POSIX.1-1988 as a standard sh builtin; present in Bash since 1.0 (1989) and remains unchanged for compatibility.

SEE ALSO

fg(1), jobs(1), disown(1), wait(1)

Copied to clipboard