Linux has many tricks up its sleeve, which helps make it one of the most powerful and flexible operating systems on the planet.
Take, for instance, the ability to schedule commands. Say you need to print something, but someone has been using the printer all morning and is showing no signs of letting up. You need to make sure the file in question is printed, but don't trust your memory. This is a greattime to schedule the file to print so thatit'll happen when you're certain the printer will be available.
Also: 5 Linux commands I use to keep my device running smoothly
Whatdo you do? Turn toat.
Theat command allows you to schedule the execution of a single instance of a command or script at a specific time and date and should be installed on your Linux distribution by default.
Essentially,at is run like so:
at [OPTION(s)] execution_time
Here, OPTION(s) is/are various options you can add, and execution_time is the time/date for the command's execution.
Also: How to share folders to your network from Linux
Withat, you can schedule the execution of a command at a specific time, a set number of minutes or hours after the current time, on a specific date/time, or even days into the future -- it's really flexible.
You can even schedule your computer's shutdown at a specific time. This can be handy if you prefer to shut your PC down at night and tend to forget.
Let's stick with our example above, printing a file at a specific time. First, command-line printing is handled with the lp command. If you only have one printer connected to your machine, you don't have to tell lp which printer to use. We'll also have to use the echo command and the pipe. It sounds complicated, but it's not. Here's how.
The first thing you'll need to do is open a terminal window on your Linux distribution. Once you've done that, verifyatis installed with the command:
at -V
You should see something like this in the output:
at version 3.2.5Please report bugs to the Debian bug tracking system (http://bugs.debian.org/)or contact the maintainers ([email protected]).
Remember when I said theat command syntax wasat [OPTION(s)] execution_time? That's just the structure of the command itself, but doesn't include the command you want to run withat.
Also: The 4 best Linux desktops based on GNOME - and what I most like about each one
Confused? You won't be. We have to employ theechocommand to construct what we wantatto run. Using our example, we'll print the file zdnet.txt using thelpcommand. For that, we'll use the following:
echo "lp zdnet.txt"
Next, we use the pipe to send the output of the first command to the at command, which looks like this:
echo "lp zdnet.txt"
The output of our first command "lp zdnet.txt" just so happens to be the command to print the file zdnet.txt.
Let's print the zdnet.txt file two hours from the current time, which would beat now + 2 hours. You could also specify a date.
Also: Don't run these 5 Linux commands - here's why
Let's say you wanted to print the file at 3pm, five days from the current date, which could be done withat 3pm + 5 days.
Our full command now looks like this:
echo "lp zdnet.txt" at now + 2 hours
If you run that command, you'll see output informing you when the command will be run. For instance, my output was:
warning: commands will be executed using /bin/shjob 1 at Mon Oct 21 10:24:00 2024
Once you've run the command, you can be sure the zdnet.txt file will print two hours from the current time.
Also: The first 5 Linux commands every new user should learn
That's how you use theat command in Linux. I would recommend going through the manual page (man at) to find out more about how to schedule specific times and dates with the command.