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
  1. -e 编辑配置
  2. -l 列出当前配置
  3. -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
  1. 分钟,取值0-59
  2. 小时,取值0-23
  3. 日期,取值1-31
  4. 月份,取值1-12,或者月份缩写jan,feb,mar,apr ...
  5. 星期/周,取值0-6,该值中,默认一周的第一天为周日,即 0 或 7 都为周日,或者可以输入缩写sun,mon,tue,wed,thu,fri,sat
  6. user-name 执行用户
  7. 命令,支持自定义脚本

其中第6项可不填,本人测试环境为CentOS 7.x,发现在设置该项后反而会失效,原因不明。


Linux crontab 使用说明
https://blog.doracoin.cc/posts/development/11943.html
作者
Doracoin
发布于
2017年10月17日
更新于
2025年8月22日
许可协议