Or copy link
Copy link
The at command in Linux is used to schedule tasks to run once at a specific time in the future. This command helps us automate the tasks by setting up commands or scripts to run at a scheduled time. The at command reads commands from standard input (stdin) and groups them into an at job, which executes only once at the scheduled time. This functionality makes it a useful tool for handling one-time scheduled tasks on Linux systems.
In this tutorial, we will walk you through different examples of Linux at command examples to schedule a job.
In most Linux distributions, the at command is not pre-installed by default. However, you can install it manually using the package manager specific to your distribution. For example, you can install the at command on Debian-based systems using apt package:
sudo apt install at
While on Red Hat-based systems, you can use the yum package as shown below:
sudo yum install at
After installing the at command, you can use it to schedule tasks to run at specific times.
at is a command line utility in Linux that enables us to schedule one-time tasks. The cron command is an alternative to at, but it’s used for recurring tasks. Unlike at, which schedules a command to run once, cron executes commands at regular intervals.
Explore the at Command With Ultahost Linux VPS!
Ultahost offers Linux hosting with NVMe SSD storage, making it easy to experiment with Linux commands. Use our cheap Linux VPS to practice and improve your command-line skills efficiently.
You need to follow the below-given syntax to use this command in Linux:
at [option] time
You can replace “option” with one of the following flags depending on your specific scheduling needs:
On the other hand, the “time” expression can be one of the following:
Read also Exploring the Linux tr Command
You can also access the at command’s manual page for a detailed understanding of this command. For this purpose, run the following command from the terminal:
man at
The manual page provides an overview of the at command, including its syntax, description, and available options:
In this section, we will discuss several examples of the Linux at command to understand its working:
The following command schedules a reboot after three minutes from now:
echo "sudo reboot" | at now + 3 minutes
Note: You can learn more about the reboot command in our dedicated guide on restarting Ubuntu from the terminal.
Use the -l option with the at command to display all the jobs currently scheduled in the queue:
at -l
Alternatively, you can run the atq command to achieve the same functionality:
atq
The output shows that a job with the number 15 is pending:
We can use the at command with the -d option to delete any pending job from the queue. For instance, the following command deletes a Job 15 from the queue:
at -d 15
You can list the remaining pending jobs to confirm that a job has been deleted:
We can execute the at command with the -m option to send an email to the user when a scheduled job runs:
cat sampleFile.txt | at -m midnight
This command schedules the execution of sampleFile.txt contents at midnight and sends an email upon completion:
sampleFile.txt
You can run the at command with the -c option to view the contents of a job that was scheduled earlier. This can be helpful if you need to recall the details of the job or verify the scheduled time. The following command shows how to view a specific scheduled job using its job number:
at -c 16
The following output shows that the at command returns the content of the job 16:
We can specify a day of the week with the at command to schedule a job at a specific day:
at Tuesday +25 minutes
This command schedules a task to run 25 minutes after the current time on the upcoming Tuesday:
We can also log the output of a scheduled job to a file using the at command:
echo "df -h > /home/anees/storageDetails.txt" | at now + 15 minutes
This command schedules a disk usage report to be saved in a file named storageDetails.txt after 15 minutes:
storageDetails.txt
This way, you can use the at command with any valid option or time expression to schedule tasks to run at specific times.
at is a command-line tool for scheduling one-time tasks in Linux. You can install it using package managers like apt or yum. Moreover, you can customize scheduling with valid options. In this article, we explored how to install at, various time expressions, and practical examples, including scheduling tasks, listing and deleting jobs, sending email notifications, and logging output.
The at command in Linux is a powerful tool for scheduling one-time tasks to run at a specific time. For seamless execution of scheduled tasks and improved system performance, consider Ultahost’s VDS hosting plans, which offer dedicated resources and optimal reliability for advanced operations.
The at command is used to schedule tasks to run once at a specific time in the future. It helps automate tasks by setting up commands or scripts to run at a scheduled time.
On Debian-based systems, you can install the at command by running “sudo apt install at“.
On Red Hat-based systems, use the “sudo yum install at” command to install the at command.
You can use the “at” command with the “-l” option or the atq command to list all scheduled jobs.
To delete a scheduled job, use “at -d job_number”. Replace job_number with the ID of the job you want to delete.
Yes, use the -m option to receive an email notification when the job is completed. For example cat sampleFile.txt | at -m midnight.
To view the contents of a specific job, you can run the “at -c job_number” command. Replace job_number with the ID of the job you want to view.
GCC (GNU Compiler Collection) is a widely used compiler...
The find command in Linux is a powerful and versatile t...
The sed command stands for stream editor is a powerful ...
Kali Linux often used for advanced penetration testing ...
The .bashrc file is a shell script that runs every time...
Plesk is a comprehensive web hosting control panel desi...
Save my name, email, and website in this browser for the next time I comment.
Δ