Pin Me

Linux Command Line: at

written by: jlwallen•edited by: Rebecca Scudder•updated: 12/8/2008

Say you want to shut your machine down at a certain time, but you can not be there to shut it down. With Linux you can do this. The "at" command allows you execute command at a specified time. The at command is a very helpful tool to automate tasks at specific times when cron is not the answer.

  • slide 1 of 3

    Why "at" not "cron"?

    The main difference between at and cron is that cron schedules regularly occurring tasks whereas at schedules one-time executions of commands. The at command is very useful for scheduling tasks that need to be taken care of when you can not be present at your computer. The at command is also a very simple means of creating single instance reminders via email, popup, or sound.

  • slide 2 of 3

    Basic Usage

    Using the at command is a bit different than using the standard command. When you use at it will be done from the at prompt to schedule an event. Also understanding how at deals with time is imperative. So let's first examine time.

    There are a number of ways you can schedule a timed event. You can use the exact time of day, you can use now + time increment, you can use day of the month + time of the day. Say, for instance, it is currently 1pm, and you want to schedule a task for 2pm that same day. You could either use: 2pm, now +60 minutes, or now +1 hour. Or say it is December 5 and you need to run a command (or application) on December 12. For that you could use december 12, now +7 days, or now +1 week.

    Now that you have a basic understanding of time, let's take a look at how the at command is used. Let's schedule a print job to occur an hour from the current time. We'll use the lp print command to print the file test.doc. The first thing to do is to issue the at command with the time necessary.The command is entered in a terminal window (such as aterm or eterm). After you enter the first line hit enter.

    at now +1 hour

    Your prompt will now look like:

    warning: commands will be executed using (in order) a) $SHELL b) login shell c) /bin/sh


    At this point you will enter the command like so:

    at> lp test.doc

    When you hit enter you will see:


    Now hit the keys "Ctrl" and "d" at the same time to reveal output that looks similar to:

    job 12 at 2008-12-05 14:24

    You now have a job in the at queue. To check this you can issue the atq command which will print out the at queue. This will only print out job numbers. As you can see, in the sample text above, the job you just created is number 12. If you want to remove the job from the queue you can issue atrm which will remove all jobs from the at queue. If you want to remove only a specific job from the queue you would first find out the job number with the atq command and then issue atrm with the job number as an argument.

    Another nice feature of at is the ability to mail to yourself the output of the command. For this you would use the -m argument. To get more output in the mail add the -v argument (for verbose). This would alter the initial command like so:

    at -m -v now +1 hour

    When this email arrives you should see the standard output as if you ran atq as well as the full command issued (atq does not list the actual command.)

  • slide 3 of 3

    Final Thoughts

    The Linux at command is an incredibly useful tool. You can get creative and use it as a simple reminder. In the command section of your at prompt you could issue something like:

    touch reminder; echo "pick up bread" > reminder; aterm -e nano /home/jlwallen/reminder

    to pop up an aterm window with the nano editor showing the text "pick up bread". Because you can string Linux commands together using the ";" character, your imagination is the only limitation to what you can do with the at command.