HxHippy

fg

Bring a job to the foreground

Overview

Resumes a job that was suspended (e.g., with Ctrl+Z) or running in the background (e.g., started with &) by bringing it to the foreground. This makes it the current job and attaches it to the terminal input/output.

Syntax

fg [JOB_SPEC]

Common Options

[JOB_SPEC]

Specifies the job to bring to the foreground. If omitted, the current job (%+) is used.

%n

Job number n (e.g., fg %1).

%string

Job whose command line begins with string (e.g., fg %vim).

%?string

Job whose command line contains string.

%+ or %%

Explicitly refers to the current job.

%-

Refers to the previous job.

Examples

$ fg

Resumes the most recently suspended or backgrounded job in the foreground.

$ fg %1

Brings job number 1 to the foreground.

$ fg %vim

Brings the most recent job whose command starts with "vim" to the foreground.

$ sleep 60 &

Start sleep in background. Then `fg` to bring it to foreground.

$ vim myfile.txt (then Ctrl+Z)

Suspend vim. Then `fg` to resume it in the foreground.

foregroundresumejobprocessshelljobspecfgbgjobs