/ factorpad.com / tech / linux-essentials / crontab-command.html
An ad-free and cookie-free website.
Beginner
Learn to schedule jobs to run automatically at the Linux command line.
Videos can also be accessed from the Linux Essentials Playlist on YouTube.
Linux crontab Command Summary with Examples (3:44)
Our forty-fourth word, or command to memorize is
crontab
from our category
System.
crontab
allows you to create and
schedule automated jobs.
-options | description |
---|---|
-l |
List crontab for the current user |
-e |
Edit crontab for the current user |
-u |
Specify a different user |
Recall that we recently covered time, and now we'll automate a command.
Before we start, it helps to think of commands as mini programs and
most follow this structure:
command -option(s) argument(s)
.
The crontab
command has
5 options and the arguments point you to the user's
crontab
file, located in one central
location.
Unlike most commands, help is not available with double-dash
--help
. With
crontab
, normally an administrator
edits a file that is read by a program called
cron
, which runs in the
background after startup.
crontab
syntax is tricky so I'll be
brief here. There are six entries. The first five set the timing, and
sixth is the command.
So why is crontab
an important command?
Well, you don't want a human to remember and to do everything on Linux
so scheduling is a vital task.
And now you know how to do that.
Okay, the best way to embed this in your memory is by typing in your own terminal window.
Find this on your Mac using a program called Terminal. On Linux use Terminal or Konsole, and currently Microsoft is adding this functionality to Windows.
Here we go. I'll show you the output first and then we'll review the
crontab
entry. Let's
cat video44.txt
, which we'll pretend
is a log file. I programmed crontab
so that every minute, a
date
command, from video 15 if you
recall, runs and is appended to this file.
Next, let's crontab -e
.
All of this up here is instructional, commented out using the pound sign
#
, and here asterisk
*
means every. So
every minute, of every hour, of every day of the month, of every month,
and every day of the week, it will run this command:
date >> ~/linux/video44.txt
.
And last, let's cat
again to see if
another log entry was appended.
Okay, very good.
Okay now you know how to use crontab
.
And you know the syntax for commands, options and arguments.
One last tip about the crontab
command.
So since cron
jobs suck system
resources, crontab
often requires
administrator privileges.
Okay, thanks for visiting today. I hope this was a helpful
introduction to the crontab
command.
For an overview of the 100 videos, the 8 quizzes, a cheat sheet, the categories and a Q&A section, visit:
To better understand this tutorial I suggest watching the video.
sleep
command,
hit Back.ps
command, click Next./ factorpad.com / tech / linux-essentials / crontab-command.html
A newly-updated free resource. Connect and refer a friend today.