Linux atq Command with Practical Examples

LinuxLinuxBeginner
Practice Now

Introduction

In this lab, you will learn how to use the atq command in Linux, which is used to list scheduled jobs or tasks. The atq command is part of the at utility, which allows you to schedule commands or scripts to run at a specific time in the future. You will start by checking if the at package is installed on your system, and then use the atq command to display a list of scheduled jobs. Additionally, you will learn how to remove scheduled jobs using the atrm command.

The lab covers the following steps:

  1. Introduction to the atq Command
  2. Listing Scheduled Jobs with atq
  3. Removing Scheduled Jobs with atrm

Linux Commands Cheat Sheet


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("`Linux`")) -.-> linux/PackagesandSoftwaresGroup(["`Packages and Softwares`"]) linux/PackagesandSoftwaresGroup -.-> linux/software("`Linux Software`") subgraph Lab Skills linux/software -.-> lab-422559{{"`Linux atq Command with Practical Examples`"}} end

Introduction to the atq Command

In this step, you will learn about the atq command in Linux, which is used to list scheduled jobs or tasks. The atq command is part of the at utility, which allows you to schedule commands or scripts to run at a specific time in the future.

To get started, let's first check if the at package is installed on your system. Run the following command:

sudo apt-get update
sudo apt-get install -y at

This will install the at package, which includes the atq command.

The atq command is used to display a list of jobs that are currently scheduled to run at a specific time in the future. To use the atq command, simply run:

atq

Example output:

3       2023-04-15 14:30 a labex
2       2023-04-15 14:00 a labex
1       2023-04-15 13:30 a labex

This output shows that there are three jobs currently scheduled to run at different times. Each job is assigned a unique job number, which can be used to identify and manage the job.

In the next step, you will learn how to remove scheduled jobs using the atrm command.

Listing Scheduled Jobs with atq

In this step, you will learn how to use the atq command to list the scheduled jobs or tasks on your system.

First, let's create a few sample jobs using the at command. Run the following commands to schedule three jobs to run at different times:

echo "echo 'Job 1 executed'" | at 13:30
echo "echo 'Job 2 executed'" | at 14:00
echo "echo 'Job 3 executed'" | at 14:30

Now, let's use the atq command to list the scheduled jobs:

atq

Example output:

3       2023-04-15 14:30 a labex
2       2023-04-15 14:00 a labex
1       2023-04-15 13:30 a labex

The output shows that there are three scheduled jobs, each with a unique job number, the scheduled time, and the user who scheduled the job (in this case, the labex user).

You can also use the atq command with additional options to customize the output. For example, to display the job numbers and scheduled times only, you can run:

atq -c

Example output:

3       2023-04-15 14:30
2       2023-04-15 14:00
1       2023-04-15 13:30

In the next step, you will learn how to remove scheduled jobs using the atrm command.

Removing Scheduled Jobs with atrm

In this step, you will learn how to use the atrm command to remove or cancel scheduled jobs or tasks.

First, let's list the currently scheduled jobs using the atq command:

atq

Example output:

3       2023-04-15 14:30 a labex
2       2023-04-15 14:00 a labex
1       2023-04-15 13:30 a labex

To remove a specific job, you can use the atrm command followed by the job number. For example, to remove the job with the number 2, run:

atrm 2

Now, let's verify that the job has been removed by running atq again:

atq

Example output:

3       2023-04-15 14:30 a labex
1       2023-04-15 13:30 a labex

As you can see, the job with the number 2 has been removed from the list of scheduled jobs.

You can also remove multiple jobs at once by specifying their job numbers separated by spaces:

atrm 1 3

This will remove the jobs with numbers 1 and 3.

If you want to remove all scheduled jobs, you can use the atrm -a command:

atrm -a

This will remove all scheduled jobs for the current user.

In the next step, you will learn about the at command, which is used to schedule the jobs that you can then manage with the atq and atrm commands.

Summary

In this lab, you learned about the atq command in Linux, which is used to list scheduled jobs or tasks. You started by checking if the at package was installed on your system and then used the atq command to display a list of currently scheduled jobs. The output showed the job number, scheduled time, and the user who scheduled the job. You also learned how to create sample jobs using the at command and then list them using atq. Finally, you explored additional options to customize the output of the atq command.

Linux Commands Cheat Sheet

Other Linux Tutorials you may like