A crontab, short for "cron table," is a configuration file used in Linux systems to schedule recurring tasks or jobs. It is a fundamental tool for Linux system administrators to automate routine tasks, such as backups, system updates, log rotation, and more. The crontab file contains a list of commands or scripts that are executed at specified intervals, allowing users to schedule tasks without manual intervention.
To view and create a crontab, one must access the Linux command line interface. There are two types of crontabs: system-wide and user-specific. The system-wide crontab applies to all users on the system and is typically located in the /etc/crontab file or in the /etc/cron.d/ directory. User-specific crontabs, on the other hand, are associated with individual user accounts and can be managed using the crontab command.
To view an existing crontab, use the following command:
crontab -l
This command lists the current crontab entries for the user executing it. If no crontab exists for the user, it will display an empty result.
To create or edit a crontab, use the following command:
crontab -e
This command opens the crontab file in the default text editor specified by the EDITOR environment variable. If EDITOR is not set, it will use the vi editor by default. Within the editor, each line represents a separate cron job entry. Each entry consists of six fields, specifying the timing and command to be executed.
The format of a cron job entry is as follows:
* * * * * command_to_be_executed
The five asterisks (*) represent the timing parameters, which determine when the command will be executed. Each asterisk corresponds to a specific time unit:
1. Minute (0-59)
2. Hour (0-23)
3. Day of the month (1-31)
4. Month (1-12)
5. Day of the week (0-7, where both 0 and 7 represent Sunday)
For example, to schedule a command to run every day at 2:30 PM, the cron job entry would be:
30 14 * * * command_to_be_executed
Once the crontab file is saved and closed, the cron daemon automatically reloads the updated crontab and starts executing the scheduled tasks accordingly.
It is important to note that the cron daemon runs with the permissions of the user who owns the crontab. Therefore, the user must have the necessary privileges to execute the specified commands or scripts successfully.
A crontab is a important tool in Linux system administration for automating recurring tasks. By understanding how to view and create crontabs, system administrators can effectively schedule and manage routine jobs, improving efficiency and reducing manual intervention.
Other recent questions and answers regarding Examination review:
- What should be considered when executing commands with cron that require root privileges or access to system directories?
- How can you schedule a task to run every minute, every hour, every day, every month, and every weekday?
- Where are user crontabs and system-wide crontabs stored?
- How many fields does a crontab consist of and what do they represent?

