Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

linux
communitycreator

What is the fg command in Linux?

abhilash

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Overview

The fg command brings a background process in your current Linux shell to the foreground.

Syntax


fg [job_spec]

Below are the available ways to use job_spec to reference a job:

  • %- – Reference to the previous job.

  • %% or %+ – Reference to the current job.

  • %number – Represents the job number, e.g., %1 or %2.

  • %String – Reference to the job started by a command containing a string.

Code


> educative> sleep 30
> ^Z
> zsh: suspended sleep 30
> educative> jobs
> [1]  + suspended sleep 30
> educative> fg
> [1]  + continued sleep 30
> educative>

Explanation

Perform the steps in the terminal below:

  1. Start the sleep process with the sleep command.

  2. Press Ctrl + Z to suspend the process created in step 1. Now the process moves to the background.

  3. Use the jobs command to list all the jobs.

  4. Use the fg command to bring the sleep process to the foreground. This can be achieved in two ways:

    • Use the fg command.

    • Use the fg %1 command because the job ID is 1 for the sleep process in the image above.

Terminal 1
Terminal

RELATED TAGS

linux
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring