Linux bg command

Updated: 11/06/2021 by Computer Hope
bg command

On Unix-like operating systems, bg is a job control command. It resumes suspended jobs in the background, returning the user to the shell prompt while the job runs.

The presence of bg is required for a shell to comply with the POSIX standard.

This page covers the bash built-in implementation of bg.

Syntax

bg [job]

Options

job Specifies the job that you want to run in the background. Job number 1 is named %1, job number 2 is named %2, etc.; %, %+, or %% refers to the current job; %- or - refers to the previous job.

Examples

In this example, let's assume we are in the bash shell.

If you initiate a process at the command line, and you want to return to the command-line prompt before the program is finished executing to do something else (e.g., check your mail, edit a text file, whatever) press Ctrl+Z and the job stops.

If you then run the command:

bg %1

The stopped job resumes operation, but remains in the background. It does not receive any input from the terminal while it's in the background, but it keeps running, and you can continue to use the shell from the command line.

cancel — Cancels a print job under the System V operating system.
fg — Resumes a suspended job and brings it to the foreground.
jobs — List the status of all running jobs.
kill — Send a signal to a process, affecting its behavior or killing it.
lpstat — List the status of the LP print services.
ps — Report the status of a process or processes.
stop — Stop a running job.