centos

centos crontab语法是什么

小樊
39
2025-10-09 07:38:42
栏目: 智能运维

CentOS中的crontab(cron table)用于设置周期性被执行的指令。其基本语法如下:

基本格式

* * * * * command_to_execute
- - - - -
| | | | |
| | | | ----- Day of the week (0 - 7) (Sunday to Saturday; 7 is also Sunday)
| | | ------- Month (1 - 12)
| | --------- Day of the month (1 - 31)
| ----------- Hour (0 - 23)
------------- Minute (0 - 59)

字段说明

特殊字符

示例

  1. 每分钟执行一次

    * * * * * /path/to/command
    
  2. 每小时的第15分钟执行一次

    15 * * * * /path/to/command
    
  3. 每天凌晨2点执行一次

    0 2 * * * /path/to/command
    
  4. 每周一至周五的上午10点执行一次

    0 10 * * 1-5 /path/to/command
    
  5. 每月的1号和15号凌晨3点执行一次

    0 3 1,15 * * /path/to/command
    

编辑crontab文件

要编辑当前用户的crontab文件,可以使用以下命令:

crontab -e

要查看当前用户的crontab文件,可以使用以下命令:

crontab -l

要删除当前用户的crontab文件,可以使用以下命令:

crontab -r

注意事项

通过这些基本语法和示例,你应该能够在CentOS系统中有效地设置和管理crontab任务。

0
看了该问题的人还看了