LinuxCommandLibrary

fg

TLDR

Bring last job to foreground

$ fg
copy
Bring specific job to foreground
$ fg %[1]
copy
Resume by job name
$ fg %[vim]
copy

SYNOPSIS

fg [jobspec]

DESCRIPTION

fg resumes a suspended or background job in the foreground. It's a shell builtin used with job control to manage processes started from the shell.
Jobs are typically suspended with Ctrl+Z or started in background with &. fg brings them back to interactive foreground execution. Without arguments, it resumes the most recent job.
fg works with the shell's job table, which tracks child processes for job control.

PARAMETERS

JOBSPEC

Job identifier: %N, %string, %%, %+, %-.
%N
Job number N.
%STRING
Job whose command starts with string.
%% or %+
Current job.
%-
Previous job.

CAVEATS

Only works in interactive shells with job control. Job numbers change as jobs complete. Background processes may have continued running.

HISTORY

fg is part of POSIX job control introduced in the C shell and later adopted by Bourne shell derivatives. It enables managing multiple processes from a single terminal.

SEE ALSO

bg(1), jobs(1), kill(1)

Copied to clipboard