The cron daemon is controlled using the crontab command. The command assumes the current user unless the -u option is specified. You can create, view, and delete crontab files using the crontab command.
Some of the options of the crontab command include:
Options | Used To |
---|---|
-e | Edit the crontab file for the current user. |
-l | View the crontab file for the current user. |
-r | Delete the current crontab file. |
-u | Create a crontab file on behalf of the specified user. |
The syntax of the crontab command is:
# crontab [options] [file/ user]
crontab Command Examples
1. Edit the crontab file for the current user:
# crontab -e
2. Edit the crontab file for a specific user:
$ sudo crontab -e -u user
3. Replace the current crontab with the contents of the given file:
# crontab path/to/file
4. View a list of existing cron jobs for current user:
# crontab -l
5. Remove all cron jobs for the current user:
# crontab -r
6. Sample job which runs at 10:00 every day (* means any value):
0 10 * * * command_to_execute
7. Sample crontab entry, which runs a command every 10 minutes:
*/10 * * * * command_to_execute
8. Sample crontab entry, which runs a certain script at 02:30 every Friday:
30 2 * * Fri /absolute/path/to/script.sh