jobs Command Guide for Listing Shell Jobs
jobs lists the jobs your current shell is managing — which ones are running, which are stopped, and which number to use with bg and fg.
What is jobs, and Why Use It?
The jobs command prints a table of the background and suspended jobs belonging to your current shell: each with a job number, a state (Running, Stopped, Done), and the command that started it. It is the control panel for the jobs you started with &, suspended with Ctrl-Z, or resumed with bg and fg — the shell’s own miniature process manager, scoped to one terminal session.
Why Learn jobs?
- You need the job number:
bgandfgtake a job number (%1,%2);jobsis how you find out which is which. - Recover after suspending:
Ctrl-Zfreezes a job;jobsshows what is frozen so you can decide to continue it in the background. - Track long-running work: a script with several
&jobs can be surveyed at a glance. - Shell-scoped truth:
jobsshows only your shell’s jobs — the complement ofps, which shows the whole system.
jobsis small — one command, one screen — but it is the missing link between starting a job with&, pausing it withCtrl-Z, and steering it withbg/fg.
1. Basic Usage: See What Is Running
# List all jobs of the current shell
jobs
# Start a job in the background, then list it
sleep 300 &
[1] 12345
jobs
Example output:
[1]+ Running sleep 300 &
[2]- Stopped vim notes.txt
[1]and[2]are job numbers — the handles forbg/fg.+marks the job that%%/+%refers to (the “current” job);-marks the previous one.
2. The State Column
| State | Meaning |
|---|---|
| Running | The job is executing. |
| Stopped | Suspended — by Ctrl-Z or SIGSTOP. |
| Done | Finished; still listed until you reap it. |
| Exit n | Finished with exit code n. |
# Show only running jobs
jobs -r
# Show only stopped jobs
jobs -s
-rfilters to running;-sfilters to stopped. A stopped job is onefgorbgaway from being alive again.
3. Job Numbers and Shortcuts
# The current job (the one with +)
fg %
# The previous job (the one with -)
fg %-
# Job number 1
fg %1
# By command name prefix
fg %sleep
# By string in the command line
fg %?vim
%%and%+mean the current job;%-and%-mean the previous one.%namematches a job whose command starts withname;%?strmatches a substring.- These shortcuts work with
bg,fg,kill, andjobsalike.
4. Keep the List Around
# Long listing: also show the command's PID
jobs -l
# Notify immediately when a job changes state
set -m # job control on (usually default in interactive shells)
notify
jobs -ladds the process ID column — useful when you want to cross-reference withps.notifymakes the shell announce state changes (“Done”) the moment they happen, instead of at the next prompt.
5. jobs vs. ps: Two Views of Processes
# All processes on the system
ps aux | grep sleep
# Only the jobs THIS shell started
jobs
jobsknows about shell jobs only — backgrounded commands, suspended commands.pssees everything: daemons, other users’ processes, and jobs from other terminals.- A job started in another terminal window is invisible to
jobs; usepsthere.
Common Pitfalls
jobsis per-shell: open a new terminal and the old jobs vanish from the list — they are still running, but this shell cannot steer them.- Job numbers are not PIDs:
bg %1takes the job number, not12345.jobs -lshows both. - Done jobs linger: finished jobs stay in the list (marked Done) until the shell notices; they are harmless but can confuse.
- Subshells hide jobs:
( sleep 100 & )starts a job in a subshell — the parent shell’sjobswill not show it. Ctrl-Zthen closing the terminal leaves the job stopped; on logout the shell may SIGHUP it. Resume or kill suspended jobs before leaving.
Related Pages
| Page | Relationship |
|---|---|
bg | Resumes a stopped job in the background — needs a jobs number. |
fg | Brings a job to the foreground — same job numbers. |
ps | System-wide process view; jobs is the shell-local one. |
kill | Can signal jobs too: kill %1. |
nohup | For jobs that must survive the shell entirely. |
jobs Cheatsheet
| Command | What It Does |
|---|---|
jobs | List the shell’s jobs. |
jobs -l | List with PIDs. |
jobs -r | Only running jobs. |
jobs -s | Only stopped jobs. |
jobs %% | The current job. |
fg %1 | Foreground job 1. |
bg %2 | Background job 2. |
kill %1 | Signal job 1. |
fg %vim | Foreground a job whose command starts with vim. |