at · Linux command

Also known as: at command · atd

On this page 7

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.

StageComponentWhat happens
SubmissionatCommands and environment are written to a job file
QueuingSpool directoryJob waits with a number, queue letter and run time
DispatchatdDaemon forks a child when the run time is reached
Execution/bin/shJob runs as the owner, without a terminal
ReportingLocal mailCaptured output is mailed to the owner
Stages of an at job from submission to completion

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.

ExpressionMeaningTypical use
at now + 30 minutesThirty minutes from submissionShort delayed action
at 02:00Next occurrence of 2 a.m.Overnight maintenance
at noon tomorrow12:00 on the following dayPlanned restart
at 17:00 Friday5 p.m. on the coming FridayEnd-of-week task
at -t 202612010300Exact POSIX timestampScripts that need precision
Common time expressions accepted by at

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 -f option reads commands from a file instead of standard input.
  • The -m option sends mail even when the job produced no output.
  • The -l and -r options 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.

ToolRecurrenceStarts whenBest suited for
atOne timeA specified future timeSingle deferred tasks
batchOne timeLoad drops below thresholdHeavy jobs on busy hosts
CronRepeatingMatching crontab fieldsRoutine periodic work
systemd timerOne time or repeatingCalendar or monotonic eventServices needing logging and dependencies
nohupNoneImmediatelyKeeping a running command alive after logout
Scheduling and detachment tools in Linux

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.

SymptomLikely causeFix
Job never runsatd service not runningEnable and start atd
Command not foundDifferent PATH or shellUse absolute paths and POSIX sh syntax
Output disappearsNo local mail deliveryRedirect output to a log file
Permission denied on submitListed in at.deny or missing from at.allowAdjust the control files
Job ran at the wrong hourTime zone or daylight saving shiftUse an explicit timestamp and check the clock
Troubleshooting at jobs

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.