Difference between /etc/crontab and "crontab -e"

44

14

What is the difference between the crontab located in /etc/crontab and the crontab that can be edited using crontab -e?

jrdioko

Posted 2011-05-29T04:58:58.640

Reputation: 8 205

Answers

53

As Ignacio said, /etc/crontab is the system wide crontab.

The format of /etc/crontab is like this:

# m h dom mon dow user      command
*   *  *   *   *  someuser  echo 'foo'

while crontab -e is per user, it's worth mentioning with no -u argument the crontab command goes to the current users crontab. You can do crontab -e -u <username> to edit a specific users crontab.

Notice in a per user crontab there is no 'user' field.

# m h  dom mon dow  command
*   *   *   *   *   echo 'foo'

An aspect of crontabs that may be confusing is that root also has its own crontab. e.g. crontab -e -u root will not edit /etc/crontab See Configuring cron.

In most Linux distros, per user crontabs are typically stored in: /var/spool/cron/crontabs/<username> (vixie-cron).

RHEL based distributions are stored in /var/spool/cron/<username>. (cronie)

skrewler

Posted 2011-05-29T04:58:58.640

Reputation: 866

FYI, the path given above is incorrect: per-user crontabs are stored in /var/spool/cron/crontabs/<username> (I tried twice to submit this simple correction.) – MartyMacGyver – 2016-01-08T18:09:59.233

1... and it's corrected now. – MartyMacGyver – 2016-01-08T19:12:43.877

Actually, it's stored in /var/spool/cron/root for root's per-user crontab on a RHEL 6 system. Haven't checked Ubuntu, but saying "typically" seems a bit of a stretch. – Wildcard – 2017-08-28T20:48:01.033

@Wildcard I think "typically" is a fair word to use. RHEL distros ship w/ "cronie" (and anacron I believe) which is their fork of ISC-Cron/vixie cron. I don't think that's a stretch, in any case I've updated my answer to include more detail. – skrewler – 2017-09-22T06:07:31.353

For a quick lookup of the paths across distros, search for the string path[crontabs] in the CFEngine "paths" library and check the context (the preceding context lines look like e.g. redhat::). There's more variation than you think; e.g. SUSE puts them in /var/spool/cron/tabs. (Abstracting distro differences is one of the reasons CFEngine was originally created, so it's often a good reference.)

– Wildcard – 2017-09-22T06:20:06.990

5

One is the system crontab and can only be edited by root, and the other is the user crontab and can be edited by a user and exists per user.

Ignacio Vazquez-Abrams

Posted 2011-05-29T04:58:58.640

Reputation: 100 516