crontab命令

发布时间 2023-08-14 18:59:06作者: 山河剑心

crontab命令用于管理 crontab 任务调度。crontab 负责按照事先设置的时间自动执行指定的系统任务或命令。
常用的 crontab 命令有:

  • crontab -e: 编辑当前用户的 crontab 任务。
  • crontab -l: 显示当前用户的 crontab 任务。
  • crontab -r: 删除当前用户的所有 crontab 任务。
  • crontab -ir: 提示并删除当前用户的所有 crontab 任务。
    其他一些常用命令:
  • crontab -u username: 编辑其他用户的 crontab 任务。
  • crontab -lerr: 显示 crontab 的错误日志。
  • crontab -u username -lerr: 显示指定用户的 crontab 错误日志。
    crontab 任务的基本格式:
# ┌───────────── minute (0 - 59)
# │ ┌───────────── hour (0 - 23)
# │ │ ┌───────────── day of the month (1 - 31)
# │ │ │ ┌───────────── month (1 - 12)
# │ │ │ │ ┌───────────── day of the week (0 - 6) (Sunday to Saturday;
# │ │ │ │ │                                   7 is also Sunday on some systems)
# │ │ │ │ │
# * * * * * command_to_execute