fg Command
Intermediate Process Management man(1)Bring a background job to the foreground
๐ 121 views
๐
Updated: Apr 29, 2026
SYNTAX
fg [JOB_SPEC]
What Does fg Do?
The fg command brings a background or suspended job to the foreground, making it the active process in your terminal. It is the complement to bg โ fg brings jobs forward, bg sends them back.
fg is a shell built-in used for job control. Without arguments, it brings the most recent background/suspended job to the foreground. With %N, it brings a specific job number.
This command is essential for interacting with background processes โ for example, bringing a text editor back to the foreground after checking something in the shell.
fg is a shell built-in used for job control. Without arguments, it brings the most recent background/suspended job to the foreground. With %N, it brings a specific job number.
This command is essential for interacting with background processes โ for example, bringing a text editor back to the foreground after checking something in the shell.
Options & Flags
| Option | Description | Example |
|---|---|---|
| %N | Bring job number N to foreground | fg %1 |
| %% | Bring current (most recent) job to foreground | fg |
| %- | Bring previous job to foreground | fg %- |
| %string | Bring job whose command starts with string | fg %vim |
Practical Examples
#1 Bring last job to foreground
Resumes the most recent background/suspended job in the foreground.
$ fg#2 Bring specific job
Brings job number 2 to the foreground.
$ fg %2#3 Bring job by name
Brings the job whose command starts with "vim" to the foreground.
$ fg %vim#4 Typical workflow
Suspend editor, run a quick command, return to editor.
$ vim file.txt
# Press Ctrl+Z to suspend
ls -la
# Check files
fg
# Back to vimTips & Best Practices
Quick task switching: Use Ctrl+Z and fg to quickly switch between editing and shell commands without opening another terminal.
fg vs bg: fg makes the job active in your terminal (you interact with it). bg runs it in background (no interaction, terminal is free).
One foreground process: Only one process can be in the foreground at a time. The previous foreground process will be suspended.
Frequently Asked Questions
How do I bring a background process to the foreground?
Type fg to bring the most recent one, or fg %N for job number N (from jobs output).
How do I return to a suspended editor?
If you pressed Ctrl+Z in vim/nano, type fg to return to it. Your editing session is preserved.
What if I have multiple background jobs?
Use jobs to list them, then fg %N to bring the specific one you want.
Related Commands
More Process Management Commands
Download Process Management Cheat Sheet
View all 31 Linux command cheat sheets โMaster Linux with Professional eBooks
Curated IT eBooks covering Linux, DevOps, Cloud, and more
Browse Books โ