Name

fg

Synopsis

fg [%jobnumber]

The built-in command fg brings a suspended or backgrounded job into the foreground. With no arguments, it selects a job, usually the most recently suspended or backgrounded one. To specify a particular job (as shown by the jobs command), supply the job number preceded by a percent sign:

fg %2

A typical sequence of job control commands is:

wc -l huge_file               Start a long job
^Z                              Suspend the job
[1]+  Stopped  wc -l huge_file
➜ bg                            Put wc into the background
[1]+ wc -l huge_file &
➜                                                       Run other commands...fg                              Bring wc into the foreground
wc -l huge_file
578394783 huge_file               The wc job finishes

Get Macintosh Terminal Pocket Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.