fg
Move background process to foreground
TLDR
Bring most recently suspended or running background job to foreground
Bring a specific job to foreground (run jobs to find the job number)
SYNOPSIS
fg [jobspec]
PARAMETERS
jobspec
Job identifier like %n (job n), %+ (current), %- (previous), or %cmd (command name). Omitting uses current job.
DESCRIPTION
The fg command is a shell builtin used in interactive shells with job control enabled to resume a backgrounded or suspended job in the foreground. When a job is started with & (background) or suspended with Ctrl+Z, it can be managed using job specifications. fg brings the specified job (or the current job if none specified) to the foreground, making it the active process. The shell waits for the job to complete, suspend, or be backgrounded again.
Job control is typically enabled in interactive non-login shells. Without it, fg has no effect. Jobs are identified by numbers assigned by the shell, visible via jobs command. Common specifications include %+ (current job), %- (previous job), %n (job n), or %string (job with command starting with string). This facilitates multitasking in terminal sessions, allowing switching between processes without new terminals.
CAVEATS
Requires job control (enabled by default in interactive shells); ineffective otherwise. Only one job at a time; targets shell's job table, not system-wide processes.
EXAMPLES
fg
fg %1 (bring job 1 to foreground)
fg %vi (job starting with 'vi')
JOB SPEC FORMATS
%+ or %%: current job
%-: previous job
%n: nth job
%string: job with command matching string
%+n or %-n: relative to current/previous.
HISTORY
Originated in BSD 4.2 (1983) for job control; POSIX.1-2008 standardized. Integral to Bourne shell descendants like Bash since 1980s.


