温馨提示×

Linux Crontab命令行语法详解

小樊
60
2025-07-13 12:07:07
栏目: 智能运维

Linux中的Crontab命令用于设置周期性被执行的指令

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

以下是一些Crontab语法的示例:

  1. 每分钟执行一次命令:
* * * * * /path/to/command
  1. 每天凌晨1点执行命令:
0 1 * * * /path/to/command
  1. 每月1号凌晨1点执行命令:
0 1 1 * * /path/to/command
  1. 每周日凌晨1点执行命令:
0 1 * * 0 /path/to/command
  1. 每小时的第15分钟执行命令:
15 * * * * /path/to/command

要编辑Crontab文件,请在终端中输入以下命令:

crontab -e

要查看当前用户的Crontab文件,请输入以下命令:

crontab -l

要删除当前用户的Crontab文件,请输入以下命令:

crontab -r

注意:在执行Crontab中的命令时,请确保使用绝对路径,而不是相对路径。此外,确保Crontab中的命令具有可执行权限。

0