>Usage
The command fg is primarily used to bring background or suspended jobs to the foreground. This lets the job run interactively and take control of the terminal. Once it’s in the foreground, the job can accept user input and output information directly to the terminal screen.
>Synopsis
>Options
fg
If used without an argument (no job ID), it brings the most recently backgrounded job in the foreground. For example, between job 1 and job 2, job 2 is the one which takes precedence.
Example 1:
-zsh
> fg
[2]+ sleep 45 &
[%job]
Brings job [%job] (a specific job by its job ID) in the foreground and resumes it in the foreground if previously stopped.
Example 2:
-zsh
> fg %2
[2]+ Running sleep 45 &
%+
Brings the most recent backgrounded job to the foreground. If you have two jobs, running or stopped, the fg %+ command will bring to the foreground only the most recent backgrounded job, job 2.
Example 3:
-zsh
> fg %+
[2]+ Running sleep 45 &
%-
Brings the second most recent job to the foreground. Like in the previous example, imagine you have two jobs, running or stopped. The command fg %- will bring to the foreground not job 2, but job 1, because it's the second most recent backgrounded job.
Example 4:
-zsh
> %-
[1]- sleep 30 &