When Linux administrators need to schedule a command, they instinctively reach for cron. While cron is incredibly powerful for recurring, permanent schedules (like running a backup script every midnight), it is a terrible tool for one-time events.
If you simply want to reboot a server in exactly two hours, or trigger a database export at 3:00 AM tonight and never do it again, you should use the at command. The at utility reads commands from the standard input and executes them once at a highly specific time.
Installing the at Utility
While cron is ubiquitous, at is sometimes omitted from minimal Linux installations.
- Ubuntu/Debian:
sudo apt install at - RHEL/CentOS:
sudo dnf install at
Once installed, ensure the daemon is actively running by typing sudo systemctl enable --now atd.
How to Schedule a One-Time Command
The syntax for at is incredibly flexible and understands natural English timeframes.
- In your terminal, type
atfollowed by the specific time you want the execution to occur. For example, to run a command in exactly 30 minutes, type:at now + 30 minutes
- Press Enter. Your standard terminal prompt will disappear, replaced by an
at>prompt. This is a temporary staging area. - Type the actual Linux command you want to execute (e.g., a system reboot):
reboot
- Press Enter. You can type multiple commands on new lines if needed.
- When you are finished entering commands, press Ctrl + D on your keyboard to save the job and exit the prompt.
The terminal will print a confirmation message like job 1 at Thu Oct 12 14:30:00 2023. You can now close the terminal; the system will handle the execution automatically.
Advanced Time Syntax Examples
The at command excels because it understands human logic. You can use any of the following formats instead of complex cron asterisks:
at 10:00 PM(Runs tonight at 10:00 PM)at 03:00 AM tomorrow(Runs during the next early morning cycle)at 4:00 PM Friday(Waits until the upcoming Friday)at teatime(A built-in alias that triggers exactly at 4:00 PM)
How to View or Cancel Pending Jobs
To see a list of all commands currently waiting to be executed, use the queue command:
atq
This will print a numbered list of jobs. If you made a mistake and want to cancel Job number 3 before it executes, use the remove command:
atrm 3