Linux / Unix: fg Command Examples

Linux / Unix: fg Command Examples

The fg (foreground) command is used to bring a background job or suspended job to the foreground in Unix and Linux systems.

Here is the basic syntax for using the fg command:

ref‮ re‬to:lautturi.com
fg [jobspec]

The jobspec argument specifies the job that you want to bring to the foreground. If you do not specify a jobspec, the fg command will bring the most recently suspended job to the foreground.

Here are some examples of using the fg command:

  1. Bring a specific job to the foreground: To bring a specific job to the foreground, you can use the job number or the job name preceded by a percent sign (%).

For example, to bring the job with job number 1 to the foreground, you can use the following command:

fg %1

To bring the job with the name myjob to the foreground, you can use the following command:

fg %myjob
  1. Bring the most recently suspended job to the foreground: To bring the most recently suspended job to the foreground, you can use the fg command without any arguments.

For example:

fg

This will bring the most recently suspended job to the foreground.

  1. Bring a stopped job to the foreground: To bring a stopped job to the foreground, you can use the fg command with the -% option.

For example:

fg -%1

This will bring the stopped job with job number 1 to the foreground.

  1. Bring all stopped jobs to the foreground: To bring all stopped jobs to the foreground, you can use the fg command with the -a option.

For example:

fg -a

This will bring all stopped jobs to the foreground.

Created Time:2017-10-29 22:09:00  Author:lautturi