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
- Scheduling a task:
To schedule a task using the
atcommand, 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 with
atis as follows:
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.
<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
-foption. Here’s an example:
at <time> -f /path/to/script.sh
/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 the
atqcommand. 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 the
atrmcommand followed by the job ID. The job ID can be obtained from the output of the
atqcommand. For example:
<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.