The “jobs” Command in Linux [6 Practical Examples]

LINUX
FUNDAMENTALS
A Complete Guide for Beginners Enroll Course Now

The jobs command is one of the process control commands in Linux. This is a pretty plain command in Linux. The function of the jobs command is to show a rundown of all background and foreground processes that are initiated by the shell. In this section, you will learn the ins and outs of the jobs command in Linux.

A. Description

The jobs command is used to display a set of jobs that are currently running in the background & the foreground in Linux. If the command prompt does not show any information that means no jobs are running at that time. By using the jobs command, you can see the process ID, job number & status of each Job. This command can be effective to view or manage the jobs running in the background or foreground of the terminal.

B. Syntax

The jobs command in Linux has an easy syntax. And the syntax is as shown below:

jobs [OPTION]
Note: In the syntax above, OPTION is enclosed by a square bracket representing that one option can be used at a time.

C. Options

A few options are available for the jobs command. I have listed them here.

There is no man page for the jobs command. Although, you can explore the help page to know more about the jobs command.

help jobs

Useful Options

  • -l, Displays the process ID, job number and status of each job
  • -n, Displays only jobs that have changed status since the last notice.
  • -p, Displays only the process ID of each job.
  • -s, Displays the jobs that are stopped.
  • -r, Displays the jobs that are running.
  • -x, Executes command in the background.
Note: The options in Linux CLI (Command Line Interface) are case-sensitive, so be alert while using them.

Practical Examples of the “jobs” Command in Linux

The jobs command in Linux is very simple to use. Here you will learn some useful examples of the jobs command in Linux.

Example 1: View Running Jobs Using the “jobs” Command in Linux

To view the jobs running in the background and in the foreground, I am using the jobs command. To do the same you can follow the steps below:

Steps to Follow >

➊ At first open the Ubuntu Terminal.

➋ Type the following command in the command prompt:

jobs

➌ Now, press the ENTER button.

Note: the “jobs -r” command also returns the jobs that are running.

Output >

In the first image below, there is nothing on the terminal screen as no jobs are running currently in the background and foreground.View Running Jobs Using the “jobs” Command in Linux But in the second image, the output shows that some jobs are running.View Running Jobs Using the “jobs” Command in Linux


Similar Readings


Example 2: View the Process ID of Each Job Using the “jobs” Command in Linux

To view the process ID  of each job running in the background and in the foreground, I am using the jobs command along with the option -p . To do the same you can follow the steps below:

Steps to Follow >

➊ At first launch the Ubuntu Terminal.

➋ Type the following command in the command prompt:

jobs -p

➌ Now, hit the ENTER button.

Output >

In the image below, the output displays the process ID of each job running.View the Process ID of Each Job Using the “jobs” Command in Linux

Example 3: View the Process ID, Job Number & Status of Each Job

To view the process ID, job number & status of each job running in the background and in the foreground, I am using the jobs command in Linux along with the option -l. To do the same you can follow the steps below:

Steps to Follow >

➊ At first open the Ubuntu Terminal.

➋ Type the following command in the command prompt:

jobs -l

➌ Now, hit the ENTER button.

Output >

In the following image, the output displays the process ID, job number & status of each job running.View the Process ID, Job Number & Status of Each Job

Example 4: View the Jobs Taken to the Background

To view the jobs that are taken to the background you can use the bg command in Linux.

Steps to Follow >

➊ Firstly launch the Terminal in Ubuntu.

➋ Type the following command in the command prompt:

bg %1
Note: %number refers to the job number.

➌ Now, hit the ENTER key.

Output >

As you can see in the image, the output is displaying the job that is running in the background.View the Jobs Taken to the Background

Example 5: View the Background Jobs Taken to the Foreground

To view the background jobs taken to the foreground you can use the fg command in Linux.

Steps to Follow >

➊ Firstly launch the Terminal in Ubuntu.

➋ Type the following command in the command prompt:

fg %1
Note: %number refers to the job number.

➌ Then, press the ENTER key.

Output >

As you can see in the image below, the output is displaying the background job that is taken to the foreground.View the Background Jobs Taken to the Foreground

Conclusion

As explained in this section, the jobs command has some uses in Linux. You’ve also found the syntax, some functional options, and the practical applications of this command. To become proficient in Linux, learn the command and its practical applications thoroughly.


Similar Readings

Rate this post
Jannatul Ferdousi Sylvie

Hi there! This is Jannatul Ferdousi Sylvie. I am one of the Linux Content Developer Executives at Softeko. I live in Dhaka, Bangladesh. I have completed my BSc. in Software Engineering from American International University-Bangladesh. You can see my projects in the GitHub account. I love traveling, shopping, cooking, and gardening. Read Full Bio

Leave a Comment