At Command in Linux
6 min read
at is a command-line utility that allows you to schedule commands to be executed at a particular time. Jobs created with
at are executed only once.
In this article, we will explain how to use
at and its companion utilities
atrm to view, delete, and create jobs to be executed at a later time.
Depending on the distribution,
at may or may not be present on your Linux system.
at is not installed, you can easily install it using the package manager of your distribution.
aton Ubuntu and Debian
sudo apt update
sudo apt install at
aton CentOS and Fedora
sudo yum install at
Once the program is installed make sure
atd, the scheduling daemon is running and set to start on boot:
sudo systemctl enable --now atd
How to Use the
The simplified syntax for the
at command is as follows:
at [OPTION...] runtime
at command takes the date and time (
runtime) when you want to execute the job as a command-line parameter, and the command to be executed from the standard input.
Let’s create a job that will be executed at 9:00 am:
Once you hit
Enter, you’ll be presented with the
at command prompt that most often starts with
at>. You also see a warning that tells you the shell in which the command will run:
warning: commands will be executed using /bin/sh at>
Enter one or more command you want to execute:
tar -xf /home/linuxize/file.tar.gz
When you’re done entering the commands, press
Ctrl-D to exit the prompt and save the job:
at> <EOT> job 4 at Tue May 5 09:00:00 2020
The command will display the job number and the execution time and date.
There are also other ways to pass the command you want to run, besides entering the command in the
at prompt. One way is to use
echo and pipe the command to
echo "command_to_be_run" | at 09:00
Another option is to use Here document :
at 09:00 <<END
To read the commands from a file instead of the standard input, invoke the command with
-f option following by the path to the file. For example, to create a job that will run the script
at 09:00 -f /home/linuxize/script.sh
By default if the command produces output,
at will send an email including the output to the user once the job is completed. Invoke
at with the
-M option to suppress the email notification:
at 09:00 -M
-m to send an email even if there is no output:
at 09:00 -m
batch or its alias
at -b schedules jobs and executes them in a batch queue when the system load level permit. By default, the jobs are executed when the system load average is below 1.5. The value of the load can be specified when invoking the
atd daemon. If the system load average is higher the specified one, the jobs will wait in the queue.
To create a job with
batch, pass the commands you want to execute:
echo "command_to_be_run" | batch
Specifying the Execution Time
at utility accepts a wide range of time specifications. You can specify time, date, and increment from the current time:
Time - To specify a time, use the
HHMMform. To indicate a 12-hour time format, use
pmafter the time. You can also use strings like
teatime(16:00). If the specified time is passed, the job will be executed the next day.
Date - The command allows you to schedule job execution on a given date. The date can be specified using the month name followed by the day and an optional year. You can use strings, such as
tomorrow, or weekday. The date can be also indicated using the
atalso accepts increments in the
now + count time-unitformat, where
countis a number and
time-unitcan be one of the following strings:
Time, date and increment can be combined, here are few examples:
Schedule a job for the coming Sunday at a time ten minutes later than the current time:
at sunday +10 minutes
Schedule a job to run at 1pm two days from now:
at 1pm + 2 days
Schedule a job to run at 12:30 Oct 21 2020:
at 12:30 102120
Schedule a job to run one hour from now:
at now +1 hours
You can also specify a time and date in the
[[CC]YY]MMDDhhmm[.ss] using the
-t option. Here is an example:
at -t 202005111321.32
By default, the jobs created with
at are scheduled in the queue named
a and jobs created with
batch are scheduled in the
Queries can have a name from
Z. Queues with lower letters run with lower niceness, which means they have priority over those with higher letters.
You can specify the queue with the
-q option. For example, to set a job in the
L queue, you would run:
at monday +2 hours -q L
Listing Pending Jobs
To list the user’s pending jobs run the
at -l command:
The output will list all jobs, one per line. Each line includes the job number, date, time, queue letter, and username.
9 Tue May 5 12:22:00 2020 a linuxize 12 Wed Oct 21 12:30:00 2020 a linuxize 15 Tue May 5 09:00:00 2020 a linuxize 6 Tue May 5 09:00:00 2020 a linuxize 13 Mon May 4 23:08:00 2020 a linuxize 11 Wed Jul 1 10:00:00 2020 a linuxize 4 Tue May 5 09:00:00 2020 a linuxize
atq is invoked as an administrative user, it will list the pending jobs of all users.
Removing Pending Jobs
To remove a pending job invoke the
at -r command followed by the job number. For example, to remove the job with number nine, you would run:
/etc/at.allow files allow you to control which users can create jobs with
batch command. The files consist of a list of usernames, one user name per line.
By default, only the
/etc/at.deny file exists and is empty, which means that all users can use the
at command. If you want to deny permission to a specific user, add the username to this file.
/etc/at.allow file exists only the users who are listed in this file can use the
If neither of the files exists, only the users with administrative privileges can use the
at utility reads commands from standard input and executes them at a later time. Unlike crontab , jobs created with
at are executed only once.
For more information about all available options of the
at command type
man at in your terminal.
If you have any questions, feel free to leave a comment.