The fg command & example usages
In this guide, we will demonstrate how to use the fg command.
Additionally, you can invoke one of the symbols shown below to reference a job on the current shell.
%- – This represents a previous job
%% or %+ – This shows the current job.
%number – This represents the job number, for instance, %3 or %4.
%String – A job started by a command that comprises a string, e.g., %ping
We will simulate sending a job to the background and then bringing it to the foreground using the fg command.
So, launch your terminal and execute the ping command as shown such that it continuously sends ICMP echo requests without stopping.
Then interrupt it by pressing CTRL + Z. This causes it to stop running in the foreground of the current shell and run to the background. Use the jobs command to displays all jobs that are currently suspended or running in the background.
Take note of the output. Here, the 1 is job_spec
Now, to bring the ping command to the foreground, use the fg command as follows:
From the output, you can see that we have brought the ping command back to the foreground. You can also run the command below, which brings to the foreground the previously suspended command.
For additional information about the fg command run: