bg Command
The bg command resumes suspended jobs and runs them in the background. It's part of job control in Linux shells, allowing you to manage multiple processes efficiently.
Syntax
Description
The bg command places jobs in the background, resuming suspended jobs or continuing stopped jobs. When a job is running in the background, you can continue using the terminal for other commands.
Key features:
- Resumes suspended jobs in background
- Allows multitasking in terminal
- Works with job control
- Can specify specific jobs by job ID
- Built-in shell command
Job Specification
| Format | Description |
|---|---|
%n |
Job number n |
%string |
Job whose command begins with string |
%?string |
Job whose command contains string |
%% or %+ |
Current job (most recent) |
%- |
Previous job |
Examples
Resume most recent suspended job
Resumes the most recently suspended job in the background
Resume specific job by number
Resumes job number 1 in the background
Resume multiple jobs
Resumes jobs 1, 2, and 3 in the background
Resume job by command name
Resumes the job whose command starts with "vim"
Resume job containing string
Resumes the job whose command contains "backup"
Complete workflow example
Complete example of suspending and resuming a job
Start command directly in background
Starts a command directly in background (alternative to bg)
Resume previous job
Resumes the previous job (second most recent)
Check all jobs
Lists all jobs with process IDs
Job Control Workflow
- Start a command: Run any command normally
- Suspend: Press
Ctrl+Zto suspend the job - Background: Use
bgto resume in background - Check status: Use
jobsto see all jobs - Foreground: Use
fgto bring job to foreground - Kill: Use
kill %nto terminate job