Scheduling Tasks Using at Command in Linux (original) (raw)

Last Updated : 28 Apr, 2026

The at command is a standard Linux utility for scheduling a command or script to run one time at a specified future time. It's the perfect tool for tasks you don't want to run right now, but also don't need to run on a repeating schedule.

Syntax:

at [-q queue] [-f file] [-mldv] TIME

at Vs cron

This is the most common point of confusion. Both schedule tasks, but they have different jobs:

To Schedule Tasks Using at Command

1. Install the at package:

On Debian/Ubuntu

sudo apt install at

On RHEL/Fedora/CentOS

sudo dnf install at

2. Start and Enable the atd Service****:**

The atd (at daemon) is the service that runs in the background and checks for jobs to execute.

Start the service

sudo systemctl start atd

Enable it to start automatically on boot

sudo systemctl enable atd

Scheduling a Job by at

**1. Type at followed by the time. This opens the interactive at> prompt.

at now + 1 minute

**2. Type the commands you want to run, one per line.

at> echo "This command ran 1 minute later" > /tmp/at_test.txt
at> /usr/bin/touch /tmp/another_file.log

**3. Press Ctrl+D to save the job.

The terminal will confirm the job is scheduled, giving you a Job ID. A minute later, you can check for the files:

ls /tmp/

at_test.txt another_file.log

cat /tmp/at_test.txt

This command ran 1 minute later

file

**Example 1: Scheduling a command to run at a specific time:

**Command:

at 2:30 PM
at> echo "Hello, World!" > ~/hello.txt
at> Ctrl+D

This example schedules the echo command to write "Hello, World!" to a file at 2:30 PM.

Scheduling Command to run at specific time

**Example 2: Using a file to specify commands:

**Command:

$ echo "ls -l" > myscript
$ at 10:00 PM -f myscript

In this example, a script file (myscript) containing the ls -l command is scheduled to run at 10:00 PM.

Using a file to specify commands

Example 3: System Shutdown at Specific Date:

**Command:

at 11:45pm July 31
at> shutdown now

In this example , the computer will shutdown on a specific date

Pasted-image

Example 4 : Delete a file on a specific Time:

**Command:

at 11:45pm
at> rm hello.txt

The hello.txt file will be removed at 11:45PM today

Pasted-image-1

Time Working in "at":

**Time Format **Example Command **What It Does
**Minutes/Hours at now + 5 minutes Runs in 5 minutes.
at now + 1 hour Runs in 1 hour.
**Specific Time at 10:30 Runs at 10:30 AM today.
at 6:00 PM Runs at 6:00 PM today.
**Keywords at noon Runs at 12:00 PM today.
at midnight Runs at 12:00 AM tonight/tomorrow.
at teatime Runs at 4:00 PM today.
**Dates at 10:30 tomorrow Runs at 10:30 AM tomorrow.
at 11:45pm July 31 Runs at the specified date and time.

Service Used by the at Command in Linux

The at command in Linux is used to schedule one-time tasks to run at a specified time in the future. It relies on the atd (at daemon) service, which runs in the background and manages the execution of these scheduled jobs.

atd Service Management of the at Command in Linux

The atd daemon handles the execution of tasks scheduled using the at command. When a user schedules a job, it is stored in the /var/spool/at directory. The atd service periodically checks this directory and executes the jobs at their scheduled time.

Components of atd Service

at Command Table:

**Command **What It Does
at [time] Interactively schedule a job for [time].
atq Lists all pending jobs in the queue.
atrm [Job ID] Removes the specified job from the queue.
at -f [script] [time] Schedules the [script] file to run at [time].
echo "cmd" | at [time] Pipes a command to be run at [time].
Ctrl+D Exits and saves your interactive at> prompt.