Operations 8 min read

Master Linux ‘at’ Command: Schedule One‑Time Tasks Easily

This guide explains how to install, configure, and use the Linux at command for one‑off task scheduling, covering interactive and non‑interactive usage, time expressions, job management with atq/atrm, and differences from cron, all with practical code examples.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Master Linux ‘at’ Command: Schedule One‑Time Tasks Easily

Installation

Most Linux distributions ship the at utility. Verify its presence and version with:

$ at -V
at version 3.1.13

If the command is missing, install it with the system package manager (e.g., sudo apt-get install at on Debian/Ubuntu or sudo yum install at on RHEL/CentOS).

The daemon atd must be running. Start and enable it via systemd: $ sudo systemctl enable --now atd Check its status with systemctl status atd.

Basic Syntax and Options

at [options] [date time]
-f <file>

: read commands from <file> instead of stdin. -q <queue>: place the job in a specific queue (queues are ordered by priority). -l or atq: list pending jobs. -d <jobid> or atrm <jobid>: delete a pending job. -m: mail the user when the job finishes (requires a working MTA).

The date time argument defines when the job runs. It can be an absolute time, a keyword, or a relative expression.

Interactive Scheduling

Enter the interactive prompt, specify the execution time, then type the commands. End input with Ctrl‑D (EOF).

$ at 11:20 AM
warning: commands will be executed using /bin/sh
at> echo "hello world" > ~/at-test.txt
at> ^D
job 3 at Mon Jul 26 11:20:00 2021

Verify the result:

$ cat ~/at-test.txt
hello world

Non‑Interactive Scheduling (Pipes)

Feed a command directly to at using a pipe or a heredoc:

$ echo "echo 'hello again' >> ~/at-test.txt" | at now + 1 minute

After one minute:

$ cat ~/at-test.txt
hello world
hello again

Time Expressions

at

understands several time formats:

Absolute numeric: YYMMDDhhmm[.ss] or CCYYMMDDhhmm[.ss].

Keywords: now, midnight, noon, teatime (4 PM), AM, PM.

Relative offsets using + and words such as minutes, hours, days, weeks, months, years.

Examples:

$ echo "rsync -av /home/tux me@myserver:/home/tux/" | at 3:30 AM tomorrow
$ echo "/opt/batch.sh ~/Pictures" | at 3:30 AM 08/01/2022
$ echo "echo hello" | at now + 3 days

Viewing and Managing the Job Queue

List pending jobs:

$ atq
3   Mon Jul 26 11:20:00 2021 a user
4   Tue Jul 27 00:00:00 2021 a user

Delete a job by its ID: $ atrm 3 Inspect the exact script that will be executed (requires root): $ sudo cat /var/spool/at/a0000101b Alternatively, use at -c <jobid> to display the job’s commands.

Important Caveats

Jobs are executed by /bin/sh. Use absolute paths or set PATH explicitly inside the job.

The environment is inherited from the submitting user, but variables such as DISPLAY are not set automatically.

Timezone handling follows the system’s local time. If the system clock changes (e.g., NTP adjustments), scheduled times may shift.

Only the job owner can delete or view their own jobs; root can manage all jobs.

Conclusion

The at utility provides a lightweight way to run one‑off commands at a specific moment, complementing the recurring nature of cron. It is suitable for ad‑hoc automation such as uploading files at night, running maintenance scripts after work hours, or any task that does not require periodic execution.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

task schedulingLinuxshellat commandcron alternative
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.