This tutorial explains Linux “fg” command, options and its usage with examples.
DESCRIPTION
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.
SYNOPSIS
fg [JobID]
jobid
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:
%Number
Refers to a job by the job number.
%String
Refers to a job whose name begins with the specified string.
%?String
Refers to a job whose name contains the specified string.
%+ OR %%
Refers to the current job.
%-
Refers to the previous job.
EXAMPLES
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 [1] Running bash download-file.sh & [2]- Running evolution & [3]+ 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:
[1] + 16477 Running Sleep 100 &
use the process ID to run the sleep 100 & command in the foreground by entering:
# fg 16477
The screen displays:
sleep
Sanfoundry Global Education & Learning Series – 1000 Linux Tutorials.
- Practice Programming MCQs
- Apply for Programming Internship
- Check Linux Books
- Check Information Technology Books