Linux crontab 使用说明
本文最后更新于:2025年8月22日 晚上
附赠一个 Cron 测试网站:https://crontab.guru/
crontab
是一个大部分Linux发行版中自带的一个定时器,可以定时执行一些操作,支持指定脚本。 命令参数 :
Usage:
crontab [options] file
crontab [options]
crontab -n [hostname]
Options:
-u <user> define user
-e edit user's crontab
-l list user's crontab
-r delete user's crontab
-i prompt before deleting
-n <host> set host in cluster to run users' crontabs
-c get host in cluster to run users' crontabs
-s selinux context
-x <mask> enable debugging
Default operation is replace, per 1003.2
- -e 编辑配置
- -l 列出当前配置
- -r 删除配置
语法 :
# For details see man 4 crontabs
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
- 分钟,取值
0-59
- 小时,取值
0-23
- 日期,取值
1-31
- 月份,取值
1-12
,或者月份缩写jan,feb,mar,apr ...
- 星期/周,取值
0-6
,该值中,默认一周的第一天为周日,即 0 或 7 都为周日,或者可以输入缩写sun,mon,tue,wed,thu,fri,sat
- user-name 执行用户
- 命令,支持自定义脚本
其中第6项可不填,本人测试环境为CentOS 7.x,发现在设置该项后反而会失效,原因不明。
Linux crontab 使用说明
https://blog.doracoin.cc/posts/development/11943.html