The at
command in Linux is used to schedule one-time or recurring tasks to be executed at a specified time in the future. It allows you to run commands or scripts at a later time without the need for manual intervention.
Here’s an overview of how to use the at
command:
- Scheduling a task:
To schedule a task using theat
command, you need to specify the time at which you want the task to run and provide the command or script you want to execute. The command or script can be entered interactively or specified from a file. The basic syntax for scheduling a task withat
is as follows:
at <time>
This will open an interactive prompt where you can enter the command(s) you want to schedule. Press Ctrl+D
when you’re done entering the commands.
Replace <time>
with the time at which you want the task to run. You can specify the time using various formats such as “HH:MM”, “HH:MM AM/PM”, or “now + X minutes/hours/days/weeks”.
For example, to schedule a task to run at 9:00 AM tomorrow, you would run:
at 9:00 AM tomorrow
After running the command, the interactive prompt will open, and you can enter the command(s) to be executed. Press Ctrl+D
to exit the prompt and schedule the task.
- Specifying a command from a file:
Instead of entering commands interactively, you can also specify a command or script from a file using the-f
option. Here’s an example:
at <time> -f /path/to/script.sh
Replace /path/to/script.sh
with the actual path to the script file you want to execute.
- Viewing scheduled tasks:
To view the list of scheduled tasks, you can use theatq
command. It will display the job IDs and execution times of the scheduled tasks. - Removing a scheduled task:
If you want to remove a scheduled task, you can use theatrm
command followed by the job ID. The job ID can be obtained from the output of theatq
command. For example:
atrm <job_id>
Replace <job_id>
with the actual job ID you want to remove.
Please note that the at
command and related utilities might not be installed by default on all Linux distributions. You can typically install them using your package manager if they are not already available.
For more detailed information and additional options related to the at
command, you can refer to the at
command’s manual page by running man at
in the terminal.