at

process managementlinux
The at command is one of the most frequently used commands in Linux/Unix-like operating systems. at The at command is used to schedule commands to be executed once at a later time. Unlike cron, which is used for recurring tasks, at is ideal for one-time scheduled tasks.

Quick Reference

Command Name:

at

Category:

process management

Platform:

linux

Basic Usage:

at [options] [arguments]

Common Use Cases

    Syntax

    at [-V] [-q queue] [-f file] [-mMlv] timespec...
    at [-V] [-q queue] [-f file] [-mMkv] [-t time]

    Options

    Option Description
    -V Output version information
    -q queue Use the specified queue (a single letter from a to z; a is highest priority)
    -f file Read the job from file rather than standard input
    -m Send mail to the user when the job has completed
    -M Never send mail to the user, even when output exists
    -l Output a list of all jobs (same as atq)
    -d job [job...] Remove the specified jobs (same as atrm)
    -v Show the time the job will be executed before reading the job
    -c job Print the job listed by atq to standard output
    -t time Run the job at the time specified in the format [[CC]YY]MMDDhhmm[.ss]

    Examples

    How to Use These Examples

    The examples below show common ways to use the at command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.

    #

    Basic Examples:

    # Schedule a command to run at 2 PM today
    at 2pm
    echo "Hello, world!" > /tmp/at_test.txt
    [Ctrl+D]
    # Schedule a command for tomorrow at 3 AM at 3am tomorrow /home/user/backup.sh [Ctrl+D]
    # Schedule using a specific date and time at 10:15 July 31, 2023 echo "Meeting reminder" | mail -s "Meeting Today" user@example.com [Ctrl+D]
    # Use a file as input at -f commands.txt 23:00

    Advanced Examples:

    # Schedule a job with specific environment settings
    at -v 2pm tomorrow
    DISPLAY=:0 notify-send "Important reminder" "Don't forget the meeting" [Ctrl+D]
    # Use batch to run when system load permits batch /home/user/cpu_intensive_task.sh [Ctrl+D] # Schedule a reboot at midnight sudo at midnight reboot [Ctrl+D] # Use specific queue (higher priority) at -q a now + 30 minutes echo "High priority job done" > /tmp/priority_job.log [Ctrl+D] # Use specific time format at -t 202312311200 echo "Happy New Year preparations" > /tmp/nye.txt [Ctrl+D]

    Try It Yourself

    Practice makes perfect! The best way to learn is by trying these examples on your own system with real files.

    Understanding Syntax

    Pay attention to the syntax coloring: commands, options, and file paths are highlighted differently.

    Notes

    Time Specifications:

    The at command accepts times in various formats:

    • HH:MM - For a specific time (e.g., 14:30)
    • midnight, noon, teatime (4pm) - Named times
    • now + count time-units - Relative times (e.g., now + 1 hour, now + 30 minutes)
    • Time units - minutes, hours, days, weeks, months, years
    • Date specification - MM/DD/YY, DD.MM.YY, or MMDDYY
    • Time specification - Time can be specified with AM/PM or in 24-hour format

    Tips and Considerations:

    • The at daemon (atd) must be running for at jobs to execute. Check with systemctl status atd.
    • All output of commands executed by at will be mailed to the user if not redirected.
    • Use atq to view scheduled jobs and atrm to remove jobs.
    • Access to at can be controlled via the /etc/at.allow and /etc/at.deny files.
    • The environment in which at commands execute is copied from when the job was created, with some exceptions.
    • Jobs are executed in the directory from which at was run.
    • The related command batch executes commands when system load levels permit.
    • Remember that at jobs run with limited environment variables - explicitly set paths if necessary.
    • Consider redirecting both standard output and standard error to a file for later inspection.

    Security Considerations:

    • Only users listed in /etc/at.allow can use at if this file exists.
    • If /etc/at.allow doesn't exist but /etc/at.deny does, all users not listed in /etc/at.deny can use at.
    • If neither file exists, only the superuser can use at (on some systems, any user can use it).
    • Empty /etc/at.deny means all users can use at, which is often the default configuration.

    Related Commands

    These commands are frequently used alongside at or serve similar purposes:

    Use Cases

    Learn By Doing

    The best way to learn Linux commands is by practicing. Try out these examples in your terminal to build muscle memory and understand how the at command works in different scenarios.

    $ at
    View All Commands