What is the Linux Crontab used for?

The crontab in Linux is a task scheduling tool that allows users to run commands or scripts automatically at specific time intervals. Cron is a daemon (background service) that runs on Unix and Unix-like systems, such as Linux, and is responsible for managing and executing scheduled tasks. Crontab is short for “CRON TABle”, which essentially means “cron task table”.

A user’s crontab file contains a list of commands or scripts, along with the schedule for each of them. Each line in the crontab file represents a scheduled task and follows a specific format that includes the following fields:

*     *     *   *    *  command-to-execute
- - - - -
| | | | |
| | | | +----- Day of the week (0 - 7) (where both 0 and 7 represent Sunday)
| | | +---------- Month (1 - 12)
| | +------------ Day of the month (1 - 31)
| +-------------- Hour (0 - 23)
+---------------- Minute (0 - 59)

For example, if you want to run a script called my-script.sh every day at 3:00 a.m., the entry in the crontab file would look like this:

0 3 * * * /ruta/del/script/my-script.sh

To manage a user’s scheduled tasks, the following commands are used:

  • crontab -e: Edit the crontab file of the current user.
  • crontab -l: Display the contents of the current user’s crontab file.
  • crontab -r: Delete the current user’s crontab file, which effectively deletes all scheduled tasks.
  • crontab -u : Execute an action (-l, -e or -r) on another user’s crontab file, if you have administrator privileges.

In summary, the crontab in Linux is a task scheduling tool that allows users to run commands or scripts automatically at specific time intervals. It is useful for performing repetitive tasks, such as performing backups, sending emails, updating databases, or running system maintenance tasks.

Scroll to Top