The fg
command brings a background process in your current Linux shell to the foreground.
fg [job_spec]
Below are the available ways to use job_spec
to reference a job:
%-
– Reference to the previous job.
%%
or %+
– Reference to the current job.
%number
– Represents the job number, e.g., %1
or %2
.
%String
– Reference to the job started by a command containing a string.
> educative> sleep 30
> ^Z
> zsh: suspended sleep 30
> educative> jobs
> [1] + suspended sleep 30
> educative> fg
> [1] + continued sleep 30
> educative>
Perform the steps in the terminal below:
Start the sleep
process with the sleep
command.
Press Ctrl + Z
to suspend the process created in step 1. Now the process moves to the background.
Use the jobs
command to list all the jobs.
Use the fg
command to bring the sleep
process to the foreground. This can be achieved in two ways:
Use the fg
command.
Use the fg %1
command because the job ID is 1
for the sleep
process in the image above.