Linux fg Command: Bring a Shell Job to the Foreground
fg brings a background or stopped job of the current shell to the foreground. It is used when you want that job to receive terminal input again or to directly check its status.
What is the fg command?
When brought to the foreground, the shell prompt waits until the job ends or is stopped again. You can check the job number with jobs. The target of fg is not the PID but the job specifier of the current shell.
Basic syntax
fg [%job number]
Installed implementations and options may vary by distribution. Use help fg to check the description on your current system.
Examples
Check current shell jobs
Check which jobs are in the background.
jobs -l
Bring a specific job to the foreground
Replace the job number in the example with the actual value.
fg %1
Stop or terminate the job again
In foreground jobs, Ctrl+Z stops, and Ctrl+C usually sends an interrupt signal.
jobs
Bring background tasks to the foreground
fg brings a job from the current shell to the terminal foreground, allowing you to interact with it or wait until it completes. First, check the job number with jobs.
jobs fg %1
For example, if you pause vim notes.txt with Ctrl+Z, bringing it back with fg %1 returns the editor screen to the terminal. The display and the return point depend on the program, so there is no fixed single-line output.
fg is not a command to take arbitrary PIDs from other terminals. If the job is already finished or is not a job of the current shell, it cannot be brought to the foreground. To pause a running program again, you generally use Ctrl+Z.
Main Options and Format
| Options/Format | Description |
|---|---|
%N |
Select job number N of the current shell. |
%+ |
Select the current job. |
%- |
Select the previous job. |
Omit argument |
Target the current job. |
Precautions when using
Processes not managed by the current shell cannot be brought with fg. In non-interactive environments, job control may be turned off. To keep long jobs running even after the terminal is closed, consider using fg or a service management method instead of tmux.
Frequently Asked Questions
In fg %1, is %1 the PID?
No. It is the current shell's job number. Use the number shown in the jobs output.
Official Documentation
The exact behavior of the option and implementation-specific differences can be checked in the official fg documentation.









