Introduction
Cron is a Linux utility for scheduling tasks that automatically run at specific intervals on Unix-like operating systems. This allows users to automate repetitive tasks such as backups, updates, and data processing without manual intervention.
This guide will show you several options to view current cron jobs scheduled in the crontab list.
Prerequisites
- A user account with root privileges.
- Access to a terminal window (Ctrl+Alt+T).
Listing Cron Jobs in Linux
Cron jobs are located in the spool directories, in tables called crontabs. Their location varies across different distributions. In Ubuntu, the tables for all users are in /var/spool/cron/crontabs, except for the root
user, whose cron jobs are located in /etc/crontab.
The /etc/crontab file contains a list of system-wide root cron jobs. To view the list, use any text editor or utility like cat, more
, or less. For example:
cat /etc/crontab
The sections below show several different methods for listing cron jobs in Linux.
List All Active Cron Jobs
Knowing how to list all active cron jobs is crucial for system administrators. The easiest way to list all active cron jobs for the current user is via the cron
utility.
Run the following command to list all scheduled cron jobs for the current user:
crontab -l
The output shows a list of cron jobs for the current user. If the current user has no scheduled jobs, the system displays a message saying no crontab for [user]
.
The output shows all the cron jobs on the system created by the root
user.
View Cron Jobs by User
By listing cron jobs for each user, you can monitor scheduled tasks and identify any issues or misconfigurations. Reviewing user-specific cron jobs helps detect unauthorized or suspicious tasks to ensure that only authorized users have scheduled jobs. This way, you reduce the risk of security breaches.
To list cron jobs that belong to a specific user, use the following syntax:
sudo crontab -u [username] -l
Replace [username]
with the actual username you want to view the jobs for. For example:
The output shows all the cron jobs for the specified user.
List Hourly Cron Jobs
Hourly cron jobs provide a way to automate tasks at regular intervals, ensuring the timely execution of critical processes and efficient resource management. To list hourly cron jobs, run the following command:
ls -la /etc/cron.hourly
The output shows all the scheduled hourly tasks on your system.
List Daily Cron Jobs
Daily cron jobs usually handle essential tasks like data backups and log rotation. They help create daily reports or perform data analytics tasks automatically. To list daily cron jobs, run the command below:
ls -la /etc/cron.daily
The output is a list of all daily cron jobs on your system.
List Weekly Cron Jobs
Weekly cron jobs are a convenient way to automate recurring tasks on a weekly basis, ensuring their consistent execution. An example of a weekly cron job is a full system backup every Sunday night.
Run the command below to display weekly cron jobs:
ls -la /etc/cron.weekly
The output shows all the cron jobs within the weekly cron jobs directory.
List Monthly Cron Jobs
Monthly cron jobs are advantageous for automating tasks that need to occur once a month, such as system backups, report generation, or database maintenance. To display monthly cron jobs, use the command below:
ls -la /etc/cron.monthly
The output lists all the cron jobs within the directory.
View Software-Specific Cron Jobs
Software-specific cron jobs are scheduled tasks that run periodically to automate specific software-related processes. These tasks are tailored to the needs of particular applications or services. Examples include daily database backups, weekly log rotation, monthly cache clearing, scheduled reports, and indexing/search updates.
To view software-specific cron tasks, list the contents of the cron.d directory:
ls -l /etc/cron.d
You can use the cat
command or a text editor to display the contents of the files in the directory and see the details for each cron job.
Note: Learn more about the Linux at command, another useful tool for scheduling jobs.
Conclusion
Now you know how to view the cron jobs on your machine. Cron is a helpful utility for scheduling tasks such as running a job at reboot. Use the commands from this guide to sort and display tasks scheduled through the cron tool.
Next, learn about cron expressions or, if you are using a different OS, see how to set up a cron job on macOS and on Windows.