fg¶
Brings a background or paused job back to the foreground, so you can see it and interact with it.

Syntax¶
fg [%JOB]
Without a job, fg uses the current job (+ in jobs).
Options¶
| Option | Description |
|---|---|
%NUMBER |
The job with this number, e.g. %2 |
%TEXT |
The job whose command starts with TEXT, e.g. %vim |
Examples¶
Get back to the editor you paused:
fg
vim /etc/nginx/nginx.conf
fg prints the command and continues it. The editor fills the terminal again, exactly
where you left it.
Bring a background job to the foreground:
fg %1
tar -czf /mnt/backup/www.tar.gz /srv/www
The shell now waits for the job again. To stop it, press Ctrl+C. To pause it again, press Ctrl+Z.
Select a job by its command:
fg %vim
vim /etc/nginx/nginx.conf
A job number that doesn't exist:
fg %7
bash: fg: %7: no such job
When do I need it?¶
- To get back to an editor or a
lessthat you paused with Ctrl+Z - To watch the output of a background job or end it with Ctrl+C
- When a background job stopped because it waits for input
Quickly look something up while editing
In vim, press Ctrl+Z, check something in the shell, and return with fg. This is
faster than quitting and reopening the file.
Forgotten paused jobs
When you try to log out with paused jobs, bash warns once: There are stopped jobs.
If you log out anyway, they are ended and unsaved changes in an editor are lost.