To schedule a Linux command for one future run, use at. The at utility queues a shell command as a job for the atd scheduler service to run once at a later time.
I’ll explain what at does and show how to schedule a one-time job.
TL;DR: Schedule a one-time Linux command
The at command queues commands for one future run, while atq lists pending jobs and atrm removes one by its job ID.
- Use at with a time expression, then enter the command and finish with Ctrl+D.
- Use atq to check the queue and atrm JOB_ID to cancel a pending job.
- Use cron for a repeating schedule, not a one-time run.
What is the At command?
The at utility is a Linux command that reads shell commands and submits them as a job to run once at a later time. The atd daemon processes queued jobs, so the utility and a running scheduler service are both needed.
A job runs in a separate shell, without an interactive terminal. Its environment and working directory are captured when submitted, subject to implementation details. Use cron when the same command must repeat on a calendar schedule.
How to schedule and manage an at job
Submit a time expression with at, provide the commands as input, then inspect the job ID that the scheduler returns. An explicit command file suits a task with more than one line because it can be reviewed before scheduling.
Step 1: Check that at is available
Install the at package with your distribution’s package manager if the command is missing. The package name is commonly at. The service name and its startup state vary by distribution, so check its documentation rather than assuming the scheduler is active.
command -v at
man at
command -v checks whether the executable is on your PATH.
Step 2: Choose a time and enter the job
Run at followed by a supported time expression. At its prompt, enter one shell command per line, then press Ctrl+D to submit the job.
at 09:00
At the at> prompt, enter the command to run, then press Ctrl+D. You can also pipe commands into at or use -f FILE to read a prepared command file. Review file contents before submitting, since the commands execute later with your account’s permissions.
at now + 1 hour
at -f /path/to/job-commands.txt 09:00
Relative expressions such as now + 1 hour and clock times such as 09:00 are common. Past times, date formats and natural-language expressions are parsed according to the local at implementation, so use man at when the exact date matters.
Step 3: Check the queued job
Run atq to see pending jobs for your account. Keep the job number returned by at because it identifies the queued task.
atq
at -c JOB_ID
atq reports the job number and scheduled time, usually with queue and owner information. The -c option prints a queued job’s command content on implementations that support it. Replace JOB_ID with the number shown by atq.
Step 4: Cancel a pending job
Use atrm with the job number to remove a job that has not started. Check atq again to confirm that the pending entry is gone.
atrm JOB_ID
atq
Cancellation applies to queued work, not a command that is already running. For a running process, identify and manage that process using the appropriate process tools.
At command errors and limits
When at rejects a job or it does not run at the expected time, check service availability, access rules and the exact local time syntax before changing system configuration.
| Symptom | What to check |
|---|---|
| at: command not found | Install the distribution’s at package, then verify with command -v at. |
| Permission denied | Check whether /etc/at.allow or /etc/at.deny restricts your account. The allow-file behavior takes precedence when that file exists. |
| Job remains pending | Confirm the atd scheduler is running using the distribution’s service documentation and check its logs. |
| Job output is missing | Jobs have no interactive terminal. Redirect output to a log file in the scheduled command, or check local mail delivery. |
Access-file behavior and command options can differ across implementations. Do not edit system access files or start services without appropriate authorization. Consult the local manual or administrator when access is centrally managed.
Use batch when work should wait for system load to permit execution rather than a fixed clock time. It is related to at but has different scheduling semantics, so check its local manual page before relying on a load threshold.
Conclusion: Use at for one-time jobs
at is suited to a command that should run once later. atq and atrm let you inspect and cancel pending jobs.
For recurring work, see how to schedule recurring tasks with cron. For help reading command manuals, see our guide to the man command.
FAQ
These answers cover common questions about using at.
Does the at command run a job more than once?
No. at schedules a one-time job. Use cron for recurring calendar schedules.
How do I see pending at jobs?
Run atq to list pending jobs for your account and note the job ID and scheduled time.
How do I remove an at job?
Run atrm followed by the job ID while the job is still pending.
