用 at、atq 和 atrm 安排一次性任务
at 工具集可以把命令排队到某个灵活指定的时间只执行一次,并支持列出和取消队列中的任务。
运行 `echo '<命令>' | at 03:30 tomorrow` 排队一个一次性任务,用 `atq` 列出待执行任务,用 `atrm <编号>` 取消。
01命令
命令
$ echo 'sudo apt update' | at 03:30 tomorrow02作用说明
对于只需执行一次的任务,at 是 cron 的补充:它支持 `now + 30 minutes`、`10pm Friday`、`03:30 tomorrow` 这类自然时间。任务从标准输入(或 -f 文件)读取命令,以提交用户的身份运行,默认通过邮件发送输出。注意 atd 必须在运行,而且很多精简系统默认没有安装 at 包。
03风险
04撤销
撤销
$ atrm <job-number> # list jobs with atq first05来源
- at(1), batch, atq, atrm - queue, examine or delete jobs for later execution依据: at and batch read commands from standard input or a specified file to be executed at a later time; atq lists the user's pending jobs; atrm deletes jobs.
最后验证: 2026-09-17 · 分类: 系统与设置