bg

>Usage

bg is a command that resumes a suspended job in the background. This is important because sending a job to the background allows the user to continue with other tasks while the backgrounded job continues to run without blocking the terminal.

>Synopsis

bg [job_spec]

>Options

bg

If used without an argument (no job ID), it resumes the most recently suspended job in the background. A job can be suspended using the Ctrl+Z command. For example, if you pause the job sleep 45, you can resume it by inputting bg.

Example 1:

Dots

-zsh

> bg


[2]+ Running sleep 45 &

[%job]

Resumes job [%job] (a specific suspended job) by its job ID in the background. If the job ID is omitted, bg defaults to resuming the most recently stopped job. In the following example, %2 specifies that job 2 should be resumed in the background.

Example 2:

Dots

-zsh

> bg %2


[2]+ Running sleep 45 &

%+

Resumes the most recent stopped job and runs it in the background. If you have two jobs running, but then stop both of them, the bg %+ command will resume only the most recent suspended job, job 2.

Example 3:

Dots

-zsh

> bg %+


[2]+ Running sleep 45 &

%-

Resumes the second most recent suspended job by running it in the background. Like in the previous example, imagine you have two jobs running, but then stop both of them. The command bg %- will resume not job 2, but job 1, because it's the second most recent paused job.

Example 4:

Dots

-zsh

> bg %-


[1]- Running sleep 30 &

>Quiz

Progress: Question ? out of ?

Question Title

Page written by Sofia Mamone