How to List Cron Jobs in Linux

List cron jobs linux

For linux to automatically perform tasks that you would otherwise have to perform yourself, such as running scripts and executing specific commands, we use a tool called cron. On Linux systems, the cron utility is the preferred way to automate the running of scripts at specific time intervals.

In this article, we’ll cover how to view/list the jobs scheduled in the crontab list.

With most Crons (e.g. Vixie-Cron - Debian/Ubuntu default, Cronie - Fedora default, Solaris Cron ...) you get the list of scheduled cron jobs for the current user via:

$ crontab -l

or for another user via

# crontab -u username -l

Alternatively, you can look up the spool files. Usually, they are saved under /var/spool/cron, e.g. for vcron, the following directory /var/spool/cron/crontabs contains all of the configured crontabs of all users - except the root user who is also able to configure jobs via the system-wide crontab, which is located at:

/etc/crontab

To view it run the following less command:

less /etc/crontab

Example structure of the crontab:

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root

# For details see man 4 crontabs

# Example of job definition:
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  * user-name  command to be executed

On my computer it looks like this:

# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# m h dom mon dow user  command
17 *    * * *   root    cd / && run-parts --report /etc/cron.hourly
25 6    * * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6    * * 7   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6    1 * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )

With cronie (default on Fedora/CentOS), there is a cron.d style config directory for system cron jobs, as well:

/etc/cron.d

As always, the cron.d directory simplifies maintaining configuration entries that are part of different packages.

For convenience, most distributions also provide a directories where linked/stored scripts are periodically executed, e.g.:

/etc/cron.daily
/etc/cron.hourly
/etc/cron.monthly
/etc/cron.weekly

How to List Hourly Cron Jobs

To list hourly cron jobs, run below command

$ ls -la /etc/cron.hourly/
total 12
drwxr-xr-x  2 root root 4096 Apr 24 20:44 .
drwxr-xr-x 96 root root 4096 May 19 17:12 ..
-rw-r--r--  1 root root  102 Feb  9  2013 .placeholder

How to List Daily Cron Jobs

We can list the daily cron jobs with the following command:

$ ls -la /etc/cron.daily/
total 72
drwxr-xr-x  2 root root  4096 Apr 24 20:46 .
drwxr-xr-x 96 root root  4096 May 19 17:12 ..
-rw-r--r--  1 root root   102 Feb  9  2013 .placeholder
-rwxr-xr-x  1 root root   376 Apr  4  2014 apport
-rwxr-xr-x  1 root root 15481 Apr 10  2014 apt
-rwxr-xr-x  1 root root   314 Feb 18  2014 aptitude
-rwxr-xr-x  1 root root   355 Jun  4  2013 bsdmainutils
-rwxr-xr-x  1 root root   256 Mar  7  2014 dpkg
-rwxr-xr-x  1 root root   372 Jan 22  2014 logrotate
-rwxr-xr-x  1 root root  1261 Sep 23  2014 man-db
-rwxr-xr-x  1 root root   435 Jun 20  2013 mlocate
-rwxr-xr-x  1 root root   249 Feb 17  2014 passwd
-rwxr-xr-x  1 root root  2417 May 13  2013 popularity-contest
-rwxr-xr-x  1 root root   214 Mar 27  2017 update-notifier-common
-rwxr-xr-x  1 root root   328 Jul 18  2014 upstart

How to List Weekly Cron Jobs

To list weekly cron jobs. Run below command

$ ls -la /etc/cron.weekly/
total 28
drwxr-xr-x  2 root root 4096 Apr 24 20:46 .
drwxr-xr-x 96 root root 4096 May 19 17:12 ..
-rw-r--r--  1 root root  102 Feb  9  2013 .placeholder
-rwxr-xr-x  1 root root  730 Feb 23  2014 apt-xapian-index
-rwxr-xr-x  1 root root  427 Apr 16  2014 fstrim
-rwxr-xr-x  1 root root  771 Sep 23  2014 man-db
-rwxr-xr-x  1 root root  211 Mar 27  2017 update-notifier-common

How to List Monthly Cron Jobs

This will list monthly cron jobs

$ ls -la /etc/cron.monthly/
total 12
drwxr-xr-x  2 root root 4096 Apr 24 20:44 .
drwxr-xr-x 96 root root 4096 May 19 17:12 ..
-rw-r--r--  1 root root  102 Feb  9  2013 .placeholder

View Software Specific Cronjobs

We can take a look at a specific cron job with cat command:

$ cd /etc/cron.daily/
$ ls -l
total 60
-rwxr-xr-x 1 root root   376 Apr  4  2014 apport
-rwxr-xr-x 1 root root 15481 Apr 10  2014 apt
-rwxr-xr-x 1 root root   314 Feb 18  2014 aptitude
-rwxr-xr-x 1 root root   355 Jun  4  2013 bsdmainutils
-rwxr-xr-x 1 root root   256 Mar  7  2014 dpkg
-rwxr-xr-x 1 root root   372 Jan 22  2014 logrotate
-rwxr-xr-x 1 root root  1261 Sep 23  2014 man-db
-rwxr-xr-x 1 root root   435 Jun 20  2013 mlocate
-rwxr-xr-x 1 root root   249 Feb 17  2014 passwd
-rwxr-xr-x 1 root root  2417 May 13  2013 popularity-contest
-rwxr-xr-x 1 root root   214 Mar 27  2017 update-notifier-common
-rwxr-xr-x 1 root root   328 Jul 18  2014 upstart

$ cat update-notifier-common 
#!/bin/sh

set -e

[ -x /usr/lib/update-notifier/package-data-downloader ] || exit 0

# Try to rerun any package data downloads that failed at package install time.
/usr/lib/update-notifier/package-data-downloader

On top of that, you can have "at" jobs (/var/spool/at/*), anacron (/etc/anacrontab and /var/spool/anacron/*)

The correct and timely execution of those scripts is managed via run-parts entries in the system crontab or via anacron.

With systemd (on Fedora, CentOS 7, etc) periodic job execution can additionally be configured via timer units. The enabled system timers can be displayed via:

$ systemctl list-timers

We have seen all of the default directories where you can find cron jobs on most linux systems. If you have any questions or comments, please post below in the comments section.

Read Also:

 

Slavisa Milojkovic 6:00 am

About Slavisa Milojkovic

Slaviša is a long time Linux user and system administrator. He was PCLinuxOS Gnome distribution developer and maintainer for several years and active opensource supporter.

Author's All Posts
Like to become part of Linoxide Team and contribute tips? Contact us here.

Comments

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

All comments are subject to moderation.