at Command in Linux

Topics Covered

Overview

The 'at' command in Linux is a powerful tool that allows users to schedule tasks to be executed at a later time. This is extremely useful when you have certain tasks that need to be run at specific times. With the 'at' command, you can schedule these tasks without needing to be present or even logged in.

Syntax of at Command in Linux

The basic syntax of the at command in Linux is as follows:

Where:

  • at: This is the actual 'at' command itself that initiates the scheduling of tasks.
  • TIME: This specifies when the task will be executed. You can enter a specific time, or use a string like 'now + 1 hour'.
  • Task: The actual task to be performed. This can be any command that could normally be entered at the command line.

Options in at Command in Linux

  1. -V: Prints the version number of 'at' command to the terminal.

    For example -

    Output:

    This command will display the version of the 'at' command that is currently installed.

  2. -q: This option is used to specify a particular queue. The 'at' command will add the task to this queue.

    For example -

    Output:

    This command will schedule the 'echo hello' command to run one minute from now, and add it to queue 'b'.

  3. -f: Read the job from the given file, rather than standard input.

    For example -

    Output:

    This command will schedule the 'script.sh' to run one hour from now.

Example Usages

  • Basic use of 'at' command to schedule a task.:

    Output:

    Explanation: This command will schedule the 'echo hello' command to run one minute from now.

  • Canceling a scheduled 'at' command task.:

    Explanation: This command will remove the 'at' job with the id 7.

Tips

  • Remember to use Ctrl-D to signify the end of input when typing the command directly into the terminal.

  • The 'atq' command can be used to view the current 'at' job queue.

Advanced Use Cases of at Command in Linux

  • Scheduling a command to run on a specific date and time.:

    Output:

    Explanation: This command will schedule the 'echo hello' command to run at 08:00 on December 31.

  • Scheduling a script to run at a relative time in the future.:

    Output:

    Explanation: This command will schedule the 'script.sh' to run one week from now.

  • Using the '-l' option to list all the jobs in the queue with their identifiers.:

    Output:

    Explanation: This command will list all 'at' jobs, showing their job ids and the times they are scheduled to run.

Conclusion

  • The 'at' command in Linux is a versatile tool for scheduling tasks to be performed at a later time.

  • The basic syntax includes the command, a time (either specific or relative), and the task to be performed.

  • There are numerous options that can be used to modify the behavior of the 'at' command, including specifying a queue, reading the job from a file, and displaying the version number.

  • The 'atq' command can be used to view current 'at' jobs, and the 'atrm' command can be used to cancel scheduled jobs.