When to use fg
Use fg to bring a shell-managed background or stopped job into the foreground. This reconnects terminal input to that job; it does not attach arbitrary processes created by another session.
Syntax
fg [%JOB]Square brackets mark optional arguments; an ellipsis means repetition. Replace example file names, user names and server addresses with your own values.
Common options and arguments
Usage examples
Run test task
sleep 120 &A temporary background job is created in the current shell.
Check job number
jobs -lJob numbers and process IDs are listed before selecting a job.
Bring the task back to the foreground
fg %1The selected job takes foreground terminal control; the shell prompt returns when it stops or exits.
Notes and limitations
- A shell builtin only affects its own jobs.
- After returning to the foreground, Ctrl+C interrupts the job, Ctrl+Z stops it.
Common questions and troubleshooting
How do I stop a foreground command temporarily?
In an interactive shell with job control, Ctrl+Z normally stops it. Inspect jobs before resuming the intended task.
Can fg recover a task from a disconnected SSH session?
Not through a new shell's job table. Use a persistent terminal multiplexer or a managed service for work that must outlive a connection.
Further help
Options vary by version and distribution. Check the installed documentation with this command: help fg.