at — Schedule One-Time Commands for Later Execution
Practical guide to at — schedule one-time commands for a specific time, pipe jobs in, manage them with atq and atrm, and run batch when system load is low.
at runs a command not on a schedule but exactly once at a later point in time – perfect for one-off maintenance, a delayed reboot or a quick reminder. Time specifications are remarkably flexible: a clock time, now + 30 minutes or simply tomorrow. It relies on the atd daemon running in the background, and you manage queued jobs with atq and atrm. When you'd rather wait until the machine is idle, reach for batch.
Schedule Jobs
at <time> — Open interactive prompt to enter commands for scheduled execution.
at 10:00echo '<command>' | at <time> — Schedule a command non-interactively.
echo 'backup.sh' | at 02:00at -f <script> <time> — Schedule a script file for execution.
at -f /home/user/maintenance.sh 23:00at now + <number> <unit> — Schedule relative to current time.
echo 'reboot' | at now + 30 minutesTime Formats
at 14:30 — Run at a specific time today (or tomorrow if past).
echo 'echo done' | at 14:30at 2:00 PM — 12-hour format with AM/PM.
echo 'echo done' | at 2:00 PMat noon — Run at noon.
echo 'run-report.sh' | at noonat midnight — Run at midnight.
echo 'cleanup.sh' | at midnightat 10:00 Jan 15 — Run at a specific date and time.
echo 'deploy.sh' | at 10:00 Jan 15at now + 1 hour — Run in one hour (units: minutes, hours, days, weeks).
echo 'check-status.sh' | at now + 1 hourat tomorrow — Run at the same time tomorrow.
echo 'reminder.sh' | at tomorrowManage Jobs
atq — List all pending at jobs for the current user.
atqat -l — List pending jobs (same as atq).
at -lat -c <job-id> — Show the content/commands of a scheduled job.
at -c 5atrm <job-id> — Remove a scheduled job.
atrm 5at -d <job-id> — Delete a scheduled job (same as atrm).
at -d 5batch Command
batch — Schedule a job to run when system load is low (< 1.5).
echo 'heavy-task.sh' | batchbatch -f <script> — Schedule a script for execution when load permits.
batch -f /home/user/rebuild-index.shCommon Patterns
echo 'systemctl restart nginx' | at 03:00 — Schedule a service restart during off-hours.
echo 'sudo systemctl restart nginx' | at 03:00echo 'wall "Maintenance in 10 minutes"' | at now + 50 minutes — Schedule a broadcast warning message.
echo 'wall "Server rebooting in 10 minutes"' | at now + 50 minutesat -M <time> — Suppress mail notification after job completion.
echo 'cleanup.sh' | at -M 02:00at -m <time> — Send mail to user even if job produces no output.
echo 'important-task.sh' | at -m 14:00 Conclusion
at is the right tool when a command needs to run exactly once at a later time – anything recurring still belongs to cron. Remember that jobs only fire while the atd daemon is running, and that /etc/at.allow and /etc/at.deny decide who may queue jobs at all. Output and errors are delivered to the user by local mail by default, so check atq and your mailbox if a scheduled job appears to have done nothing.
Further Reading
- at(1) man page – official manual page for at, atq, atrm and batch
- Ubuntu manpage: at – Ubuntu's manual page for scheduling one-time jobs with at and batch