Fg command on Linux (processes in the foreground) [Basic Guide]

The fg command on Linux does the exact opposite of the bg command, placing the task or background process in the foreground and connected to a terminal.

It also accepts that a job number is passed as a parameter.

In this example again the find command is placed in the background with Ctrl-Z and it gains the number of Job1:

$ find/-iname a* 2>/dev/null ^Z [1] + Stopped find/-iname a* 2> /dev/null

To view programs running in the background, the jobs command can be executed:

$ jobs [1] + Stopped find/-iname a* 2> /dev/null

To return the Job to the foreground and connected to the terminal, simply run fg. In this example, the Job number was passed as a parameter:

$ fg 1 find/-iname a* 2> /dev/null

Learn much more about Linux in our online course. You can register here. If you already have an account, or want to create one, just log in or create your user here.

Did you like it?

Share

Uirá Endy Ribeiro

Uirá Endy Ribeiro is a Software Developer and Cloud Computing Architect with a 23-year career. He has master's degrees in computer science and fifteen IT certifications and is the author of 11 books recognized in the IT world market. He is also Director at Universidade Salgado de Oliveira and Director of the Linux Professional Institute - LPI Director's Board.

Leave a Reply 0

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.

Need help?