When you need to automate a task in Linux, cron is the standard tool. However, cron is designed for recurring tasks (like running a backup every midnight). If you simply need a script to run exactly one time—say, three hours from now, or at 5:00 PM on Friday—writing a complex cron job and then remembering to delete it later is highly inefficient. Instead, you should use the at command.
Step 1: Install the ‘at’ utility
The at command is not always installed by default on modern lightweight distributions. To install it on Ubuntu/Debian, run:
sudo apt update && sudo apt install at
Step 2: Schedule the Command
Using at is incredibly intuitive because it accepts natural language time formats.
- In your terminal, type
atfollowed by the time you want the command to execute. For example:
at 5:00 PMorat now + 2 hours - Press Enter. You will be dropped into an interactive prompt that looks like this:
at> - Type the exact command or script path you want to run (e.g.,
/opt/scripts/backup.sh) and press Enter. - You can add multiple commands on new lines if needed.
- When you are finished, press Ctrl + D on your keyboard to save and exit.
The terminal will print a confirmation message showing the exact job number and the date and time it is scheduled to execute.
How to View and Cancel Scheduled Jobs
If you change your mind and need to cancel the execution, you can easily manage your queue.
- To see a list of all your currently scheduled
atjobs, run:atq - To delete a specific job before it runs, look at its ID number from the
atqoutput, and runatrm [ID](for example:atrm 3).