at is the Linux command that schedules a one-time job to run at a specified future time. The user types shell commands into at, the tool stores them as a job in a spool directory, and the atd daemon starts that job once the time arrives, then forgets it. Within Linux process management, it fills the gap between running a command now and defining a permanent recurring schedule.
Because each job becomes an ordinary non-interactive process started by atd, understanding at also means understanding how Linux rebuilds a job environment, where output goes and which users are allowed to queue work. The command belongs to the classic Unix toolset and is specified by POSIX, although Linux distributions ship it as a separate package that must be installed and enabled.
How the at command queues and runs a job
The at command works by saving a shell script to a spool directory and letting a background service execute it later. When a user runs at 23:30, at reads commands from standard input until end of file, then writes a job file that contains those commands together with a snapshot of the environment: the current working directory, the umask and most exported variables.
The atd daemon checks the spool periodically and whenever a new job is submitted. When a job is due, atd forks a child process, switches to the submitting user’s identity, and runs the job file with /bin/sh. The job has no controlling terminal, so it cannot read keyboard input, and anything it prints is collected and sent by local mail to the owner unless output is redirected.
The lifecycle follows a fixed sequence of stages, which the table below lists with the component responsible for each one.
| Stage | Component | What happens |
|---|---|---|
| Submission | at | Commands and environment are written to a job file |
| Queuing | Spool directory | Job waits with a number, queue letter and run time |
| Dispatch | atd | Daemon forks a child when the run time is reached |
| Execution | /bin/sh | Job runs as the owner, without a terminal |
| Reporting | Local mail | Captured output is mailed to the owner |
If the machine is powered off at the scheduled moment, atd runs overdue jobs as soon as it starts again, because the job file still sits in the spool. This behavior differs from many timer designs and matters for maintenance windows.
Time specifications and companion commands
The at command accepts a flexible time grammar that ranges from exact timestamps to relative offsets. Times are interpreted in the local time zone of the system, so administrators who manage servers in UTC should confirm the clock setting before relying on wall-clock expressions.
| Expression | Meaning | Typical use |
|---|---|---|
at now + 30 minutes | Thirty minutes from submission | Short delayed action |
at 02:00 | Next occurrence of 2 a.m. | Overnight maintenance |
at noon tomorrow | 12:00 on the following day | Planned restart |
at 17:00 Friday | 5 p.m. on the coming Friday | End-of-week task |
at -t 202612010300 | Exact POSIX timestamp | Scripts that need precision |
Several companion commands manage the queue. atq lists pending jobs with their numbers, atrm removes a job by number, and at -c prints the full job script, which is the quickest way to inspect the captured environment. The batch command submits a job that runs only when the system load average falls below a threshold, by default 0.8 on most Linux builds.
- Queue letters from a to z group jobs; later letters run at a higher nice value, which lowers their scheduling priority.
- The
-foption reads commands from a file instead of standard input. - The
-moption sends mail even when the job produced no output. - The
-land-roptions are aliases for atq and atrm.
at compared with cron, systemd timers and nohup
The essential difference is that at runs a job once, while cron and systemd timers repeat. Choosing the wrong tool leads either to forgotten recurring entries or to fragile one-off scheduling built from loops and sleep calls.
| Tool | Recurrence | Starts when | Best suited for |
|---|---|---|---|
| at | One time | A specified future time | Single deferred tasks |
| batch | One time | Load drops below threshold | Heavy jobs on busy hosts |
| Cron | Repeating | Matching crontab fields | Routine periodic work |
| systemd timer | One time or repeating | Calendar or monotonic event | Services needing logging and dependencies |
| nohup | None | Immediately | Keeping a running command alive after logout |
A transient systemd timer, created with systemd-run --on-calendar, can replace at on modern distributions and adds journal logging and resource limits through cgroups. at remains attractive for its minimal syntax and its portability across Unix systems.
Access control, environment and security
Access to the at command is governed by two control files. If /etc/at.allow exists, only users listed in it may submit jobs. If it does not exist, /etc/at.deny is consulted and every user not listed there is allowed. When neither file exists, typically only root may use at.
Because jobs inherit the environment captured at submission, a job may behave differently from an interactive session. PATH and working directory are preserved, but the job runs under /bin/sh rather than the user’s login shell, so Bash-specific syntax can fail. Writing absolute paths and explicit redirections makes jobs predictable.
From a security standpoint, at is a known persistence mechanism: an attacker with shell access can queue a delayed payload that survives logout. Hardening guides therefore recommend restricting at.allow to administrators, disabling atd where it is unused, and including the spool directory in integrity monitoring and audit rules.
Common mistakes and how to avoid them
Most at failures come from environment assumptions or from a stopped daemon rather than from the time syntax itself. The following table pairs typical symptoms with their causes and fixes.
| Symptom | Likely cause | Fix |
|---|---|---|
| Job never runs | atd service not running | Enable and start atd |
| Command not found | Different PATH or shell | Use absolute paths and POSIX sh syntax |
| Output disappears | No local mail delivery | Redirect output to a log file |
| Permission denied on submit | Listed in at.deny or missing from at.allow | Adjust the control files |
| Job ran at the wrong hour | Time zone or daylight saving shift | Use an explicit timestamp and check the clock |
A further misconception is that atrm stops a job that is already running. It only removes pending jobs; a running job is an ordinary process tree and must be ended with kill or pkill.
In everyday language
The at command is like leaving a note for the computer that says: at this exact time, do this task once. The user writes the instructions, sets the hour, and walks away. A small helper program keeps the note and carries it out when the clock reaches that moment.
Unlike an alarm that rings every morning, the note is used once and then thrown away. If the computer was switched off at the chosen time, the helper does the task as soon as the machine is back on.
Seen in the real world
A system administrator at a regional hospital must apply a database configuration change that requires a service restart, and the approved maintenance window opens at 2:00 a.m. on Sunday. Instead of staying awake, the administrator writes a short script that stops the service, applies the change, starts the service again and writes a status line to a log file, then submits it with at 02:00 Sunday -f /root/maint.sh.
Before leaving, the administrator runs atq to confirm the job number and at -c to verify that PATH and the working directory are correct. At 2:00 a.m. atd launches the job, the restart takes about four minutes, and the log file records success. On Monday morning the administrator reads the log and the mailed output, and the change was completed inside the window without anyone being present.