How To List All current Cron Jobs in Linux
This post will guide you how to list all scheduled cron jobs for the current logging user on your Linux operating system. How do I display all running cron jobs under a Linux operating system.
- What is cron
- Crontab Command
- List All Scheduled Cron Jobs
- List All Cron Jobs by User
- List Hourly Cron Jobs
- List Daily Cron Jobs
- List Weekly Cron Jobs
- List Monthly Cron Jobs
What is cron
cron is started automatically from /etc/init.d on entering multi-user runlevels. cron is a daemon to execute scheduled commands. cron searches its spool area (/var/spool/cron/crontabs) for crontab files (which are named after accounts in /etc/passwd); crontabs found are loaded into memory. cron also reads /etc/crontab, which is in a slightly different format.
Crontab Command
crontab is the program used to install, deinstall or list the tables used to drive the cron(8) daemon in Vixie Cron. Each user can have their own crontab, and though these are files in /var/spool/cron/crontabs, they are not intended to be edited directly.
The syntax of the Crontab command are as followss:
crontab [ -u user ] file crontab [ -u user ] [ -i ] { -e | -l | -r } Options:
The -l option causes the current crontab to be displayed on standard output. See the note under DEBIAN SPECIFIC below. The -r option causes the current crontab to be removed. The -e option is used to edit the current crontab using the editor specified by the VISUAL or EDITOR environment variables. After you exit from the editor, the modified crontab will be installed automatically. If neither of the environment variables is defined, then the default editor /usr/bin/editor is used.
List All Scheduled Cron Jobs
If you want to list all scheduled cron jobs for you current logging use in your Linux system, and you can use the crontab command with “-l” option, type:
$ crontab -l
Outputs:
devops@devops:~$ crontab -l # Edit this file to introduce tasks to be run by cron. # # Each task to run has to be defined through a single line # indicating with different fields when the task will be run # and what command to run for the task # # To define the time you can provide concrete values for # minute (m), hour (h), day of month (dom), month (mon), # and day of week (dow) or use '*' in these fields (for 'any').# # Notice that tasks will be started based on the cron's system # daemon's notion of time and timezones. # # Output of the crontab jobs (including errors) is sent through # email to the user the crontab file belongs to (unless redirected). # # For example, you can run a backup of all your user accounts # at 5 a.m every week with: # 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/ # # For more information see the manual pages of crontab(5) and cron(8) # # m h dom mon dow command 0 1 * * 1 df -h > /tmp1 0 2 * * 1 cat /var/log/message >tmp2
If you want to display Root user cron jobs, and you can show contents of the /etc/crontab file with cat or less command, type:
$ sudo less /etc/crontab
or
$ sudo cat /etc/crontab
Outputs:
devops@devops:~$ sudo cat /etc/crontab # /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 ) #
And if you want to update your root user cron jobs, and you need to edit /etc/crontab file.
List All Cron Jobs by User
If you only want to show all cron jobs by a given user, and you can use crontab command with -u option, type:
$ sudo crontab -u username -l $ sudo crontab -u devops -l
Outputs:
devops@devops:~$ crontab -u devops -l
# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h dom mon dow command
0 1 * * 1 df -h > /tmp1
0 2 * * 1 cat /var/log/message >tmp2
List Hourly Cron Jobs
If you want to list hourly cron jobs in your Linux system, and you can check file names under /etc/cron.hourly directory, type:
$ ls -la /etc/cron.hourly
Outputs:
devops@devops:~$ ls -la /etc/cron.hourly
total 20
drwxr-xr-x 2 root root 4096 Feb 9 2019 .
drwxr-xr-x 145 root root 12288 Oct 2 23:49 ..
-rw-r--r-- 1 root root 102 Nov 16 2017 .placeholder
List Daily Cron Jobs
If you want to list daily cron jobs in your Linux system, and you can use the following command:
$ ls -la /etc/cron.daily
Outputs:
devops@devops:~$ ls -la /etc/cron.daily
total 1176
drwxr-xr-x 2 root root 4096 Oct 3 02:24 .
drwxr-xr-x 145 root root 12288 Oct 2 23:49 ..
-rwxr-xr-x 1 root root 311 May 29 2017 0anacron
-rwxr-xr-x 1 root root 539 Oct 10 2018 apache2
-rwxr-xr-x 1 root root 376 Nov 20 2017 apport
-rwxr-xr-x 1 root root 1478 Apr 20 2018 apt-compat
-rwxr-xr-x 1 root root 355 Dec 29 2017 bsdmainutils
-rwxr-xr-x 1 root root 384 Dec 12 2012 cracklib-runtime
-rwxr-xr-x 1 root root 1176 Nov 2 2017 dpkg
-rwxr-xr-x 1 root root 170760 Oct 3 02:24 less
-rwxr-xr-x 1 root root 10256 Oct 3 02:24 lessecho
-rwxr-xr-x 1 root root 8564 Oct 3 02:24 lessfile
-rwxr-xr-x 1 root root 19856 Oct 3 02:24 lesskey
-rwxr-xr-x 1 root root 8564 Oct 3 02:24 lesspipe
-rwxr-xr-x 1 root root 67808 Oct 3 02:24 ln
-rwxr-xr-x 1 root root 211528 Oct 3 02:24 loadkeys
-rwxr-xr-x 1 root root 52664 Oct 3 02:24 login
-rwxr-xr-x 1 root root 51280 Oct 3 02:24 loginctl
-rwxr-xr-x 1 root root 372 Aug 21 2017 logrotate
-rwxr-xr-x 1 root root 109232 Oct 3 02:24 lowntfs-3g
-rwxr-xr-x 1 root root 133792 Oct 3 02:24 ls
-rwxr-xr-x 1 root root 84048 Oct 3 02:24 lsblk
-rwxr-xr-x 1 root root 149688 Oct 3 02:24 lsmod
-rwxr-xr-x 1 root root 1065 Apr 7 2018 man-db
-rwxr-xr-x 1 root root 538 Mar 1 2018 mlocate
-rwxr-xr-x 1 root root 1387 Dec 13 2017 ntp
-rwxr-xr-x 1 root root 249 Jan 25 2018 passwd
-rw-r--r-- 1 root root 102 Nov 16 2017 .placeholder
-rwxr-xr-x 1 root root 3477 Feb 20 2018 popularity-contest
-rwxr-xr-x 1 root root 383 Mar 29 2019 samba
-rwxrwxr-x 1 root root 14602 May 21 22:50 slack
-rwxr-xr-x 1 root root 246 Mar 21 2018 ubuntu-advantage-tools
-rwxr-xr-x 1 root root 214 Jun 27 2018 update-notifier-common
List Weekly Cron Jobs
If you want to list all weekly cron jobs, just type the following command:
$ ls -la /etc/cron.weekly
Outputs:
devops@devops:~$ ls -la /etc/cron.weekly
total 32
drwxr-xr-x 2 root root 4096 Jun 4 07:33 .
drwxr-xr-x 145 root root 12288 Oct 2 23:49 ..
-rwxr-xr-x 1 root root 312 May 29 2017 0anacron
-rwxr-xr-x 1 root root 723 Apr 7 2018 man-db
-rw-r--r-- 1 root root 102 Nov 16 2017 .placeholder
-rwxr-xr-x 1 root root 211 Jun 27 2018 update-notifier-common
List Monthly Cron Jobs
if you want to display all monthly cron jobs on your current Linux system, type:
$ ls -la /etc/cron.monthly
Outputs:
devops@devops:~$ ls -la /etc/cron.monthly
total 24
drwxr-xr-x 2 root root 4096 Feb 9 2019 .
drwxr-xr-x 145 root root 12288 Oct 2 23:49 ..
-rwxr-xr-x 1 root root 313 May 29 2017 0anacron
-rw-r--r-- 1 root root 102 Nov 16 2017 .placeholder
Conclusion
You should know that how to display all cron jobs or daily/monthly/weekly cron jobs using crontab command in your Linux system.