LinuxDevOps

How to Display, List, and View Current Cron Jobs in Linux OS

Introduction

Cron jobs list is an important part of any Linux system administrator’s toolkit. These automated tasks enable you to schedule commands or scripts to run at specific times or intervals. As a result, you free up to focus on more essential tasks. However, as your system grows and the number of cron jobs increases, it can become challenging to keep track of everything. That’s where knowing how to display, list, and view current cron jobs can be incredibly helpful.

In this guide, you will get insights into the basics of cron jobs. You will learn some simple ways to display, list, and view current cron jobs in Linux OS. Whether you’re a seasoned Linux administrator or just starting, these tips will help you streamline your workflow and ensure that your cron jobs are running smoothly. So let’s dive in!

Also Read: How to Setup Cron Job in Linux

Easy Step to Listing all Active Cron Jobs in Linux OS

Easy Step to Listing all Active Cron Jobs in Linux OS

Listing all Active Cron Jobs Running

Here are steps to list all active cron jobs running on a Linux OS:

1. Open the terminal: Launch the terminal on your Linux OS by clicking on the Terminal icon or using the shortcut Ctrl+Alt+T  and login to the server using the below command

           ssh [email protected] -p0000   
Here: root is the user, xx.xx.xx.xx is the IP address of the server, 0000 is the SSH port no. of the server

2. Type the command to list all active cron jobs: For listing all active cron jobs running on your system, enter the following command in your terminal and press Enter:

sudo crontab -l        ( no need to use sudo if you have root  access)

This command will display the current user’s crontab file, which contains all the active cron jobs running on the system.

Active cron jobs running on the system

3. View the cron job information: After running the above command, you will see the details of all the active cron jobs in the terminal. The output will incorporate details such as the schedule, the command to run, and the user account under which the command will run.

4. Understand the cron job schedule: The first part of the cron job information represents the schedule. The schedule is defined by five fields that specify the minute, hour, day of the month, month, and day of the week when the command should run.

5. Analyze the command: The second part of the cron job information specifies the command to run at the scheduled time. This field will give you a better understanding of what each cron job is doing and what process it’s responsible for.

6. Troubleshoot any issues: In case you notice any issues with the output, you can edit the crontab file and remove or modify the existing cron jobs using the command:

sudo crontab -e

By following these steps, you will be able to view all the active cron jobs running on your Linux OS, and troubleshoot any issues that may arise.

Active cron jobs running on your Linux

Viewing Cron Jobs by User

Here are the steps to view cron jobs by user in Linux:

  1. Open the terminal on your Linux system.
  2. Type the command crontab -u [username] -l and press Enter. Replace [username] with the actual username whose cron jobs you want to view.
  3. The terminal will display a list of all the cron jobs that are scheduled for the specified user.

Note: If you want to view the cron jobs for the root user, you can omit the -u [username] option and simply type crontab -l in the terminal.

Listing Hourly Cron Jobs

To list all the hourly cron jobs that are currently active, you can use the following command:

sudo ls -l /etc/cron.hourly

This command will display a list of all the scripts that are scheduled to run on an hourly basis. 

List of all the scripts that are scheduled to run on an hourly basis
List of all the scripts that are scheduled to run on an hourly basis

Each line in the output will contain the following information:

  • Permissions: This indicates the access permissions for the script.
  • Number of links: This indicates the number of hard links to the script.
  • Owner: This indicates the user that owns the script.
  • Group: This indicates the group that the script belongs to.
  • Size: This indicates the size of the script in bytes.
  • Date and time: This indicates the date and time that the script was last modified.
  • Name: This indicates the name of the script.

Similarly, you can list the daily, weekly, and monthly cron jobs daily by replacing the keyword of “hourly” from the above command with the daily, weekly, or monthly, as you require. 

If you want to view the contents of a particular script, you can use the following command:

sudo cat /etc/cron.hourly/<script-name>

Replace <script-name> with the name of the script that you want to view. This command will display the contents of the script in the terminal.

Viewing Software-Specific Cron Jobs

To view software-specific cron jobs, you need to follow these steps:

1. Open your terminal or command prompt.

2. Type the following command to view all the cron jobs set up on your system:

crontab -l

3. Scroll down to the software-specific cron job that you want to view. It will typically start with the name of the software or the user who set it up.

4. If you have multiple users on your system, you can use the following command to view the cron jobs for a specific user:

crontab -u <username> -l

Replace <username> with the name of the user whose cron jobs you want to view.

5. Once you have located the software-specific cron job, note down its schedule and command.

6. You can also edit or delete the cron job using the crontab command. To edit the cron job, use the following command:

crontab -e

This will open the cron job file in your system’s default editor. Edit the cron job as required and save the file.

8. To delete the cron job, use the following command:

crontab -r

This will remove all cron jobs set up for the current user. If you want to remove the cron job for a specific user, use the following command:

crontab -u <username> -r

Replace <username> with the name of the user whose cron jobs you want to remove.

By following these steps, you can view, edit, or remove software-specific cron jobs on your Linux system.

Also Read: Linux SCP Command: Essential Tips for Seamless File Transfer

Conclusion

Managing cron jobs on a Linux system is a crucial task for any system administrator. The ability to display, list, and view current cron jobs in Linux OS can help ensure that critical tasks are executed at the appropriate times. By using the simple methods outlined in this guide, you can easily display, list, and view current cron jobs in Linux oS These methods can help you save time and increase your productivity by automating routine tasks. Remember to test your cron jobs regularly and monitor their execution to ensure that they are running as expected. With the right tools and knowledge, managing cron jobs on Linux can be a breeze.

Arpit Saini

He is the Chief Technology Officer at Hostbillo Hosting Solution and also follows a passion to break complex tech topics into practical and easy-to-understand articles. He loves to write about Web Hosting, Software, Virtualization, Cloud Computing, and much more.

Related Articles

Leave a Reply

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