LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

bg

Resume suspended jobs in the background

TLDR

Resume the most recently stopped job in the background
$ bg
copy
Resume a specific job by number
$ bg %[1]
copy
Resume a job whose command begins with a string
$ bg %[string]
copy

SYNOPSIS

bg [job-spec]

DESCRIPTION

bg resumes suspended jobs in the background. It is a shell built-in command that continues execution of jobs that were stopped (typically with Ctrl+Z) while allowing continued use of the terminal. If no job is specified, the most recently stopped job is resumed.The command is part of POSIX shell job control functionality and is available in bash, zsh, ksh, and other POSIX-compatible shells.

PARAMETERS

job-spec

Job identifier (%1, %2, etc.)
If no job specified, bg operates on the most recently stopped job.

JOB SPECIFICATIONS

%n

Job number n
%string
Job whose command begins with string
%?string
Job whose command contains string
%% or %+
Current job
%-
Previous job

WORKFLOW

$ # Start long-running command
./long_process

# Suspend with Ctrl+Z
[Ctrl+Z]

# Resume in background
bg

# Or resume specific job
bg %1

# List jobs
jobs

# Bring to foreground
fg %1
copy

CAVEATS

Only works with job control enabled shells. Backgrounded jobs may stop if they try to read from terminal. Output still goes to terminal unless redirected. Jobs terminate when shell exits unless using nohup or disown.

HISTORY

bg has been part of job control in Unix shells since the C shell (csh) introduced the feature in the late 1970s.

SEE ALSO

fg(1), jobs(1), disown(1), nohup(1)

Copied to clipboard
Kai