WebMasterCampus
WEB DEVELOPER Resources

Linux bg Command

Learn Linux bg Command with examples


Linux bg Command

In Linux, we can use “bg” command is used to place foreground jobs in background.

In Linux, bg is a job control command. It resumes suspended jobs in the background, returning the user to the shell prompt while the job runs.

bg Command Syntax

>> bg [job_spec ...] 

bg Command Job Spec

job_spec Description
%n Refer to job number n.
%str Refer to a job which was started by a command beginning with str.
%?str Refer to a job which was started by a command containing str.
%% or %+ Refer to the current job. fg and bg will operate on this job if no job_spec is given.
%- Refer to the previous job.

Steps to see bg Command working

We use jobs command to list all jobs

>> jobs

We create a process using sleep command, we get its ID as 1.

>> sleep 200

^Z
[1]+  Stopped                 sleep 200

We put it in background by providing its ID to bg.

>> bg %1

[1]+ sleep 200 &

Let’s use jobs -r command again to list all running jobs.

>> jobs -r

[1]+  Running                 sleep 200 &

bg –help Command

bg –help command displays help information.

>> bg –help
Created with love and passion.