Open In App

bg command in Linux with Examples

Last Updated : 06 Nov, 2025
Comments
Improve
Suggest changes
3 Likes
Like
Report

In Linux, the bg command is a useful tool that allows you to manage and move processes between the foreground and background. It's especially helpful when you want to multitask in the terminal by placing a process in the background, enabling you to continue using the terminal for other commands while the process runs quietly in the background.

Example of bg Command in Linux

Step 1: Start a long-running process (e.g., sleep 60).

sleep 6

Step 2: Suspend the process by pressing Ctrl + Z.

Output:

[1]+  Stopped                 sleep 60

Step 3: Resume the suspended process in the background using bg.

bg

Output:

[1]+ sleep 60 &
file
  • The process sleep 60 resumes execution in the background.
  • You can verify it by running the jobs command:

Syntax

bg [job_spec ...]

where,

  • job_spec: This is used to identify the job you want to move to the background. It can be specified in several formats:
  • %n: Refers to job number n.
  • %str: Refers to a job that was started by a command beginning with str.
  • %?str: Refers to a job that was started by a command containing str.
  • %% or %+: Refers to the current job. Both fg and bg commands will operate on this job if no job_spec is provided.
  • %-: Refers to the previous job.

If no job_spec is provided, the most recent job is resumed in the background.

Useful Options for bg command

1. bg [JOB_SPEC]:

This command is used to put the mentioned job in background. In the below screenshot, we do following : bg [JOB_SPEC]'sleep 500' is used to create dummy foreground job.

  • We use jobs command to list all jobs
  • We create a process using sleep command, we get its ID as 1.
  • We put it in background by providing its ID to bg.

2. bg --help:

Displays the help information for the bg command. This is useful if you need more information on how to use the command or if you're unsure of the available options. bg --help


Explore