Bash — The bg Built-in

Learn how Bash’s bg built-in lets you resume stopped jobs in the background without interrupting your terminal session. Discover how to use Ctrl+Z, bg, and jobs, understand job specifications, and learn when to use bg instead of fg or &.

Bash — The bg Built-in

Linux can run many processes simultaneously, and Bash provides job control to manage commands launched from an interactive shell. You can run commands in the foreground, where they occupy the terminal, or in the background, where the shell can accept further commands.

But what if a command is already running in the foreground and you want to continue it without keeping the terminal occupied?

That's where Bash's bg built-in comes in.

The bg command resumes a stopped job in the background, allowing it to continue running while you use the shell.

Foreground, background, and stopped jobs

Consider a command that takes a while to finish:

sleep 300

It runs in the foreground, so Bash doesn't display another prompt until it finishes. If you want to suspend it without terminating it, press Ctrl+Z.

Bash reports something similar to:

^Z
[1]+  Stopped                 sleep 300

The job is now stopped, and your shell prompt is available again.

To resume it in the background, run:

bg

Bash may respond:

[1]+ sleep 300 &

The job continues running, and you can enter other commands.

The basic workflow is:

Foreground job
      │
   Ctrl+Z
      ▼
  Stopped job
      │
      │ bg
      ▼
 Background job

Remember: Ctrl+Z suspends the job; bg resumes it in the background.

Syntax and job specifications

The syntax is:

bg [job_spec]

You can run bg without an argument to resume the current job, or specify a particular job:

bg %1

Here, %1 refers to Bash job number 1.

A job number is not a process ID (PID). Bash assigns job numbers within the current shell, while the operating system assigns PIDs to processes.

For example:

[1]+  Stopped                 sleep 300

The [1] identifies the Bash job. The process itself might have a PID such as 27451.

You can inspect job numbers and PIDs with:

jobs -l

Example:

[1]+ 27451 Stopped                 sleep 300

Use %1 when referring to job 1 with bg, not its PID.

Managing multiple jobs

Bash can keep track of several jobs in one interactive shell.

For example, suspend two commands with Ctrl+Z and resume each with bg. You can then inspect their states:

jobs

Example output:

[1]-  Running                 sleep 300 &
[2]+  Running                 sleep 600 &

Resume a particular stopped job with:

bg %1

Or:

bg %2

These commands are useful when the selected job is stopped. Running bg on a job that is already running in the background is generally unnecessary.

You can also refer to jobs using other Bash job specifications:

Job specificationMeaning
%1Job number 1
%% or %+Current job
%-Previous job
%?textA job whose command line contains text
%prefixA job whose command begins with prefix, if unambiguous

For everyday use, numeric job specifications are usually the clearest.

bg versus &

Both are associated with background execution, but they serve different purposes.

If you know beforehand that a command should run in the background, append &:

make -j8 &

Bash starts the command asynchronously and returns the prompt. It may display a job number and PID:

[1] 27451

By contrast, bg resumes a job that has already been stopped.

For example, if you start a compilation normally:

make -j8

you can press Ctrl+Z and then run:

bg %1

This lets the compilation continue without occupying the foreground.

In short:

  • command & starts a new command in the background.
  • Ctrl+Z, followed by bg, suspends and then resumes an existing foreground job.

bg versus fg and kill

Bash provides several job-control commands that serve different purposes.

CommandPurpose
bg %1Resume job 1 in the background
fg %1Bring job 1 to the foreground
kill %1Send a signal to job 1
jobsList jobs managed by the current shell

For example, you might suspend an editor with Ctrl+Z, run another command, and then bring the editor back:

fg %1

Unlike bg, which resumes the job without assigning it the terminal's foreground role, fg brings it back to the foreground.

kill is different again: it sends a signal rather than resuming a job.

Practical considerations

Background output

Putting a command in the background doesn't automatically redirect its output. A command may continue printing messages to your terminal even after the prompt returns.

To save its output to a file, use:

long-command >output.log 2>&1 &

To discard both standard output and standard error:

long-command >/dev/null 2>&1 &

These are examples of starting a command directly in the background; output redirection is separate from the operation of bg.

Interactive commands

A background job that attempts to read from the controlling terminal may be suspended by the shell. Consequently, bgis generally more convenient for tasks that don't require interactive input.

For long-running interactive work that must survive terminal disconnection, consider a terminal multiplexer such as tmux or screen rather than relying solely on shell job control.

When no suitable job exists

If you run bg without a suitable current job, Bash reports an error. Check the available jobs first:

jobs

This also helps you confirm whether a job is stopped or already running.

Common mistakes

Expecting Ctrl+Z to start background execution. It suspends the job. You must run bg to resume it in the background.

Confusing job numbers with PIDs. Use bg %1 for Bash job 1. The PID shown by jobs -l is a different identifier.

Using bg to launch a new command. Use command & to start a new background command. Use bg to resume a stopped job.

Assuming background jobs are silent. Redirect output when appropriate, or the job may continue writing to your terminal.

Quick reference

CommandWhat it does
Ctrl+ZSuspend the foreground job
bgResume the current job in the background
bg %1Resume job 1 in the background
jobsList jobs and their states
jobs -lInclude process IDs
fg %1Resume job 1 in the foreground
command &Start a new command in the background

Conclusion

The Bash bg built-in lets you resume a stopped job in the background instead of terminating it or waiting for it to finish in the foreground.

The essential workflow is simple:

# Start a command
make -j8

Press Ctrl+Z, then run:

bg

Use jobs to inspect the job's state and bg %1 to select a particular job.

Once you understand the difference between a stopped job, a background job, and a foreground job, Bash job control becomes much easier to use. And when you need a background job back in the terminal, fg is the next command to learn.

Read next

Bash — The fg Built-in

Learn how Bash’s fg built-in brings background and suspended jobs back to the foreground. Discover how to use fg, bg, and jobs, understand job numbers, and manage running commands without restarting them.

Bash — The dirs Built-in

A concise excerpt for the `dirs` post: > Learn how Bash’s `dirs` built-in lets you inspect and manage the directory stack. Explore `-p`, `-l`, `-v`, and `-c`, select specific entries, combine options, and see how `dirs` works together with `pushd` and `popd`.

Bash — The do Keyword

Here’s a short excerpt for the post: > Learn how Bash uses the `do` keyword to mark the beginning of a loop body. Explore how `do` works with `for`, `while`, and `until`, how it pairs with `done`, and how to write clean, readable Bash loops.