# 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.

Source: https://www.jpkc.com/db/en/cheatsheets/shell-system/at/

<!-- PROSE:intro -->
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`.
<!-- PROSE:intro:end -->

## Schedule Jobs

`at <time>` — Open interactive prompt to enter commands for scheduled execution.

```bash
at 10:00
```

`echo '<command>' | at <time>` — Schedule a command non-interactively.

```bash
echo 'backup.sh' | at 02:00
```

`at -f <script> <time>` — Schedule a script file for execution.

```bash
at -f /home/user/maintenance.sh 23:00
```

`at now + <number> <unit>` — Schedule relative to current time.

```bash
echo 'reboot' | at now + 30 minutes
```

## Time Formats

`at 14:30` — Run at a specific time today (or tomorrow if past).

```bash
echo 'echo done' | at 14:30
```

`at 2:00 PM` — 12-hour format with AM/PM.

```bash
echo 'echo done' | at 2:00 PM
```

`at noon` — Run at noon.

```bash
echo 'run-report.sh' | at noon
```

`at midnight` — Run at midnight.

```bash
echo 'cleanup.sh' | at midnight
```

`at 10:00 Jan 15` — Run at a specific date and time.

```bash
echo 'deploy.sh' | at 10:00 Jan 15
```

`at now + 1 hour` — Run in one hour (units: minutes, hours, days, weeks).

```bash
echo 'check-status.sh' | at now + 1 hour
```

`at tomorrow` — Run at the same time tomorrow.

```bash
echo 'reminder.sh' | at tomorrow
```

## Manage Jobs

`atq` — List all pending at jobs for the current user.

```bash
atq
```

`at -l` — List pending jobs (same as atq).

```bash
at -l
```

`at -c <job-id>` — Show the content/commands of a scheduled job.

```bash
at -c 5
```

`atrm <job-id>` — Remove a scheduled job.

```bash
atrm 5
```

`at -d <job-id>` — Delete a scheduled job (same as atrm).

```bash
at -d 5
```

## batch Command

`batch` — Schedule a job to run when system load is low (< 1.5).

```bash
echo 'heavy-task.sh' | batch
```

`batch -f <script>` — Schedule a script for execution when load permits.

```bash
batch -f /home/user/rebuild-index.sh
```

## Common Patterns

`echo 'systemctl restart nginx' | at 03:00` — Schedule a service restart during off-hours.

```bash
echo 'sudo systemctl restart nginx' | at 03:00
```

`echo 'wall "Maintenance in 10 minutes"' | at now + 50 minutes` — Schedule a broadcast warning message.

```bash
echo 'wall "Server rebooting in 10 minutes"' | at now + 50 minutes
```

`at -M <time>` — Suppress mail notification after job completion.

```bash
echo 'cleanup.sh' | at -M 02:00
```

`at -m <time>` — Send mail to user even if job produces no output.

```bash
echo 'important-task.sh' | at -m 14:00
```

<!-- PROSE:outro -->
## 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](https://manpages.debian.org/bookworm/at/at.1.en.html) – official manual page for at, atq, atrm and batch
- [Ubuntu manpage: at](https://manpages.ubuntu.com/manpages/noble/en/man1/at.1.html) – Ubuntu's manual page for scheduling one-time jobs with at and batch
<!-- PROSE:outro:end -->

## Related Commands

- [crontab](https://www.jpkc.com/db/en/cheatsheets/shell-system/crontab/) – schedules recurring tasks via the cron table
- [systemctl](https://www.jpkc.com/db/en/cheatsheets/shell-system/systemctl/) – controls systemd services and timers as a modern scheduling alternative
- [nohup](https://www.jpkc.com/db/en/cheatsheets/shell-system/nohup/) – keeps commands running after you log out

