This tutorial explains Linux “fg” command, options and its usage with examples.
Resume job in the foreground, and make it the current job. If job is not present, the shell’s notion of the current job is used. The return value is that of the command placed into the foreground, or failure if run when job control is disabled or, when run with job control enabled, if jobid does not specify a valid job or jobid specifies a job that was started without job control.
Simply put, You can bring a background job to the foreground using fg command. When executed without arguments, it will take the most recent background job to the foreground.
Specifies the job that you want to run in the background.
The JobID parameter can be a process ID number, or you can use one of the following symbol combinations:
Refers to a job by the job number.
Refers to a job whose name begins with the specified string.
Refers to a job whose name contains the specified string.
%+ OR %%
Refers to the current job.
Refers to the previous job.
1. Simple Example
If you have multiple background ground jobs, and would want to bring a certain job to the foreground, execute jobs command which will show the job id and command.
In the following example, fg %1 will bring the job#1 (i.e download-file.sh) to the foreground.
# jobs  Running bash download-file.sh & - Running evolution & + Done nautilus . # fg %1
2. Bring Specific job using jobid to foreground
If the output of the jobs -l command shows the following job running in the background:
 + 16477 Running Sleep 100 &
use the process ID to run the sleep 100 & command in the foreground by entering:
# fg 16477
The screen displays:
Sanfoundry Global Education & Learning Series – 1000 Linux Tutorials.
- Apply for Linux Internship
- Practice Programming MCQs
- Buy Linux Books
- Buy Information Technology Books
- Apply for Programming Internship