November 3, 2024

How to List or Display all Cron Jobs in Linux

Cron is a command-line job scheduler available on Linux operating systems that allows users to schedule jobs at specified intervals, including hourly, daily, weekly, and monthly. This is called system-wide crontab.

Cron jobs are defined in files called crontabs, and each user have their own crontab file, and the superuser can view crontabs owned by other users.

crontab is short for ‘cron table’, which consists of three parts (time, username, and command or script). A cron job is an actual command or script that you run in the background at a specific scheduled time.

[Schedule_Time] [User_Name] [Command_to_be_Executed]

In this quick tutorial, you will learn how to list and display all types of cronjobs scheduled on your Linux system.

Listing Cron Jobs of Current User

The default ‘crontab -l’ command displays the contents of your own crontab file. I logged in as root, so it shows root user cronjobs below.

crontab -l

0  1  *	*  1	/usr/local/psa/libexec/modules/watchdog/cp/secur-check
0  1  *	*  1	/usr/local/psa/libexec/modules/watchdog/cp/send-report weekly
10 1  *	*  *	/usr/local/psa/libexec/modules/watchdog/cp/clean-sysstats
15 1  *	*  *	/usr/local/psa/libexec/modules/watchdog/cp/pack-sysstats day
15 1  *	*  1	/usr/local/psa/libexec/modules/watchdog/cp/pack-sysstats week
15 1  1	*  *	/usr/local/psa/libexec/modules/watchdog/cp/pack-sysstats month
15 1  1	*  *	/usr/local/psa/libexec/modules/watchdog/cp/pack-sysstats year
20 1  *	*  *	/usr/local/psa/libexec/modules/watchdog/cp/clean-events
0  3  *	*  7	/usr/local/psa/libexec/modules/watchdog/cp/clean-reports
47 23 *	*  *	/usr/sbin/ntpdate -b -s 2.pool.ntp.org

Displaying Cron Jobs of Other User

A root or sudo privileged user can also view scheduled cron jobs of other users. To do so, use the following syntax. Replace the username you want to view cron jobs with the actual username.

crontab -u [User_Name] -l

For example, to check the scheduled cron jobs of the 'fosstechi' user from root, you need to execute:

crontab -u fosstechi -l

0  3  *	* *  /bin/bash /opt/scripts/fosstechi-website-backup.sh
0  4  *	* *  /bin/bash /opt/scripts/fosstechi-db-backup.sh

Listing Cron Jobs by Time

Time-based cronjobs are located in several directories such as hourly, daily, weekly and monthly in Linux. You can drop cronjob in the respective directory based on your needs.

1) View Hourly Cron Jobs

Check the /etc/cron.hourly directory to find all cron jobs scheduled to run every hour. According to the below output, five cronjobs are scheduled to execute every hour.

ls -lh /etc/cron.hourly

total 20K
-rwxr-xr-x. 1 root root 392 May 16 19:58 0anacron
-rwxr-xr-x. 1 root root 362 Oct  1  2020 0yum-hourly.cron
-rwxr-xr-x. 1 root root 199 Jul 27 17:35 50plesk-hourly
-rwxr-x---. 1 root root 172 Jan 10  2023 awstats
-rwxr-xr-x. 1 root root 582 Jun  7 21:02 plesk-php-cleanuper

2) View Daily Cron Jobs

Similarly, you can check the /etc/cron.daily directory to find all cron jobs scheduled to run daily basis. As per the below output, there are eight cronjobs scheduled to execute on a daily basis.

ls -lh /etc/cron.daily

total 32K
-rwxr-xr-x. 1 root root 211 Jan 12  2017 00webalizer
-rwxr-xr-x. 1 root root 332 Oct  1  2020 0yum-daily.cron
-rwxr-xr-x. 1 root root 314 Jul 27 17:35 50plesk-daily
-rwxr-xr-x. 1 root root 448 Jul  3 16:07 60sa-update
-rwxr-xr-x. 1 root root 129 Jul  6 21:07 dmarc-report
-rwx------. 1 root root 219 Apr  1  2020 logrotate
-rwxr-xr-x. 1 root root 618 Oct 30  2018 man-db.cron
-rwxr-xr-x. 1 root root 754 May 16 16:32 plesk-rrd-cleaner

3) View Weekly Cron Jobs

Similarly, you can check the /etc/cron.weekly directory to find all cron jobs scheduled to run weekly. As per the output below, three cronjobs are scheduled to be executed weekly.

ls -lh /etc/cron.weekly

total 12K
-rwxr-xr-x. 1 root root 199 Jul 27 17:35 50plesk-weekly
-rwxr-xr-x. 1 root root 457 Jul 19 12:02 fail2ban-vacuum
-rwxr-xr-x. 1 root root 142 Jul 28 15:59 plesk-remove-temp-backups

4) View Monthly Cron Jobs

Similarly, you can check the /etc/cron.monthly directory to find all cron jobs scheduled to run monthly. According to the below output, only one cronjob is scheduled to run monthly.

ls -lh /etc/cron.monthly

total 4.0K
-rwxr-xr-x. 1 root root 200 Jul 27 17:35 50plesk-monthly

Viewing System-Wide Cron Jobs

The system-wide root cron jobs can be found in the /etc/crontab file. You must be superuser in order to view this cronjob.

Listing System-Wide Cron Jobs

Listing Application Specific Cron Jobs

Application specific cronjobs can be found in multiple cron directories. However, application-related routine tasks are dropped into the /etc/cron.d directory by some applications.

ls -lh /etc/cron.d

total 12K
-rw-r--r--. 1 root root 128 May 16 19:58 0hourly
-rw-r--r--. 1 root root 122 May 20 10:22 plesk-backup-manager-task
-rw-r--r--. 1 root root  71 May 20 12:20 sa-update

Displaying All Users Cron Jobs

All user cron jobs are typically located in the spool ‘/var/spool/cron’ directory on RHEL based system, whereas Debian and Ubuntu cronjobs are stored in ‘/var/spool/cron/crontabs’ directory. A separate file is created for all the user accounts with their name.

To list the cronjobs of all users, use the ls command as shown below:

ls -lh /var/spool/cron

total 1.5M
-rw-------. 1 root root   10 May 20 20:46 2daygeek
-rw-------. 1 root root   10 May 20 12:45 fosstechi
-rw-------. 1 root root   10 May 20 12:43 linuxtechnews
-rw-------. 1 root root   10 May 20 12:43 mageshcoin

Final Thoughts

In this article, we have described how to list or view cron jobs on a Linux system. Cronjobs can be executed on demand based on time spread across multiple locations on an hourly, daily, weekly or monthly basis.

If you have any questions or feedback, feel free to comment below.

Leave a Reply

%d bloggers like this: