• Home
  • LLMs
  • Docker
  • Kubernetes
  • Java
  • All
  • About
Linux-Ubuntu | crontab
  1. Notes
  2. Examples
  3. Command Help (man crontab)

  1. Notes
    The crontab command is used to manage a list of commands that have to be run on a specific schedule.
    Each user can have his own crontab.

    If the file "/usr/lib/cron/cron.allow" exists, then the user name must be listed therein, otherwise the user will not be allowed to use the crontab command.

    If the file "/usr/lib/cron/cron.deny" exists, then the user name must not be listed therein, otherwise the user will not be allowed to use the crontab command.
  2. Examples
    • Manage the crontab of the current user.
      $ crontab -e
      # this command "echo `date` >> /home/user1/crontab_test.log" will be executed every minute
      * * * * * echo `date` >> /home/user1/crontab_test.log

      Save and exit. You will see the following messages in the standard output:
      # crontab: no crontab for user1 - using an empty one
      # crontab: installing new crontab

      You can check if the crontab is installed:
      $ crontab -l
      * * * * * echo `date` >> /home/user1/crontab_test.log

      You can list the crontab of all users:
      $ sudo ls -l /usr/lib/cron/tabs
      -rw-------  1 root  root  284 14 Feb 09:00 user1

      You can check the crontab excution:
      $ cat /home/user1/crontab_test.log
      Sun Feb 25 09:01:00 EST 2014
      Sun Feb 25 09:02:00 EST 2014
      Sun Feb 25 09:03:00 EST 2014
      Sun Feb 25 09:04:00 EST 2014

    • Manage the crontab of another user.
      $ sudo crontab -e -u user2
      # this command "echo `date` >> /home/user2/crontab_test.log" will be executed every minute
      * * * * * echo `date` >> /home/user2/crontab_test.log

      # save and exit. You will see the following messages in the standard output:
      crontab: no crontab for user2 - using an empty one
      crontab: installing new crontab

      You can check if the crontab is installed:
      $ sudo ls -l /usr/lib/cron/tabs
      -rw-------  1 root  root  285 14 Feb 09:35 user2
      -rw-------  1 root  root  284 14 Feb 09:00 user1
  3. Command Help (man crontab)
    • The following options can be used:
      -u
      |Specify the name of the user whose crontab is to be used.
      |If this option is not given, the crontab of the current user is used.
      |This option is important when using "su" to run the crontab command.
      
      -l
      |Display the current crontab on standard output.
      
      -r
      |Remove the current crontab.
      
      -e
      |Edit the crontab using the editor specified by the VISUAL or EDITOR environment variables.
      |After exiting the editor, the modified crontab will be applied automatically.

    • Add crontab entries.
      Each entry in the crontab may have the following syntax "min hour day month day_of_week" where:
      min: [0 - 59]
      
      hour: [0 - 23]
      
      day: [1 - 31]
      
      month: [1 - 12]
      
      day of week: [0 - 7] (check your system if 0 or 7 reference Sunday)

    • You can also use the following patterns to match a value of the schedule:
      *: match any value of the allowed values
      
      -: specify a range of values: 9-15 (means any value between 9 and 15)
      
      ,: specify a list of values or range of values: 7,9-15,35 (means 7, any value between 9 and 15, and 35)
      
      /: specify steps over a range of values: */3 (for hours, every 3 hours), 8/2 (for hours, every 2 hours starting from 8h)
      
      name_of_the_day: use the first three letters of the day (ranges or lists of names are not allowed)
      
      name_of_the_month: use the first three letters of the month (ranges or lists of names are not allowed)
© 2025  mtitek