Linux bg Command: Resume a Shell Job in the Background

bg resumes a stopped job in the background in Bash. It is used when you want to stop a running command with Ctrl+Z and continue using the terminal.

What is the bg command?

bg sends a continue signal to a stopped job but does not give front control of the terminal. You can check the job number with jobs and specify it like %1. Interactive programs waiting for input may stop again in the background.

Basic syntax

bg [%job number]

The installed implementation and options may vary depending on the distribution. Check the description for your system with help bg.

Examples

Checking stopped jobs

After pressing Ctrl+Z during a foreground command execution, check the status.

jobs -s

Resuming a specific job in the background

In the example, replace %1 with the actual number from the jobs output.

bg %1

Check resume result

Check if it is in the Running state.

jobs -l

Running a Paused Job in the Background

bg continues a job that is currently paused in the background of the current shell. For example, after running sleep 60 and stopping it with Ctrl+Z, check the job number.

jobs
bg %1
jobs

Example of state changes:

[1]+  Stopped  sleep 60
[1]+  Running  sleep 60 &

%1 refers to job number 1 in the current shell, not the PID. If the shell does not support job control or there are no paused jobs, bg will fail. When a job finishes, it may disappear from jobs, so check the status again.

Main Options and Format

Options/Format Description
%N Specify job number N of the current shell.
%+ Specify the current job.
%- Specify the previous job.
Omit argument Use the job that Bash considers the current job.

Precautions when using

A job stopped with Ctrl+Z is not yet running. A job that tries to read from standard input may be stopped again even if resumed with bg. bg is a shell job control feature and cannot be applied to processes started in another terminal.

Frequently Asked Questions

Are appending & at the end of a command and using bg the same?

& starts the command in the background from the beginning, while bg resumes a currently stopped job in the shell in the background.

Official Documentation

The exact behavior of these options and implementation differences can be found in the official bg documentation.

More in This Category
Linux ssh-copy-id Command: Install a Public Key on a Remote Account

Linux ssh-copy-id Command: Install a Public Key on a Remote Account

Learn how to install a Public Key on a Remote Account with the Linux ssh-copy-id command, including practical examples, key options, and important precautions.

Linux fmt Command: Reformat Plain-Text Paragraphs

Linux fmt Command: Reformat Plain-Text Paragraphs

Learn how to reformat Plain-Text Paragraphs with the Linux fmt command, including practical examples, key options, and important precautions.

Linux Tutorial / PID and PPID Explained: Find and Manage Processes

Linux Tutorial / PID and PPID Explained: Find and Manage Processes

Understand what PID and PPID mean, inspect parent-child process relationships with ps and pgrep, and safely terminate a process you started yourself.

Linux modinfo Command: Inspect Kernel Module Details

Linux modinfo Command: Inspect Kernel Module Details

Learn how to inspect Kernel Module Details with the Linux modinfo command, including practical examples, key options, and important precautions.

Linux cut Command: Extract Characters and Fields

Linux cut Command: Extract Characters and Fields

Learn how to extract Characters and Fields with the Linux cut command, including practical examples, key options, and important precautions.

Linux host Command: Look Up DNS Names and Addresses

Linux host Command: Look Up DNS Names and Addresses

Learn how to look Up DNS Names and Addresses with the Linux host command, including practical examples, key options, and important precautions.

Linux lsblk Command: Inspect Disks, Partitions, and Mounts

Linux lsblk Command: Inspect Disks, Partitions, and Mounts

Learn how to inspect Disks, Partitions, and Mounts with the Linux lsblk command, including practical examples, key options, and important precautions.

Linux stat Command: Display Detailed File Metadata

Linux stat Command: Display Detailed File Metadata

Learn how to use the Linux stat command to inspect file size, permissions, ownership, timestamps, inode, and filesystem metadata, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux whoami Command: Show the Effective User Name

Linux whoami Command: Show the Effective User Name

Learn how to show the Effective User Name with the Linux whoami command, including practical examples, key options, and important precautions.

Linux timedatectl Command: Check Time Zone and Time Synchronization

Linux timedatectl Command: Check Time Zone and Time Synchronization

Learn how to check Time Zone and Time Synchronization with the Linux timedatectl command, including practical examples, key options, and important precautions.