What Are Cron Jobs In Linux?

If you are wondering what cron jobs are I will give you a very simple explanation of the answer.

If you want to know what a cron job is very simple, CRON is a daemon in Linux which means It runs continually, looking for events that cause It to spring Into action.

For example, you can use cron jobs to run scripts by the minute, hourly, daily, weekly, monthly, yearly - you get the picture...

Cron is different in that unlike most daemons, that are network servers, cron responds to events by time. Specifically, it wakes up once a minute, examines configuration files In the /var/spool/cron and /etc/fron.d directories and the /etc/crontab file and then executes the command contained In these configuration files If the time matches the time listed In the files.

One example you can use cron jobs Is to make daily backups of your server on a daily basis

# cat /etc/crontab

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/

# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly

If you want to list all of your current schedules cron jobs send this command:

# crontab -l

NOTE: you must be logged Is as superuser (root)

Here is a little snippet to help you with the time frames:

# ┌───────────── minute (0 - 59)
# │ ┌───────────── hour (0 - 23)
# │ │ ┌───────────── day of month (1 - 31)
# │ │ │ ┌───────────── month (1 - 12)
# │ │ │ │ ┌───────────── day of week (0 - 6) (Sunday to Saturday;
# │ │ │ │ │                                       7 is also Sunday on some systems)
# │ │ │ │ │
# │ │ │ │ │
# * * * * *  command_to_execute

another helpful command is the crontables, you can list it with this command:

crontab -l

to add or edit your crontables use this command:

crontab -e

if this is the first time using this command you might get a prompt to choose your default editor, this is what I go while using Ubuntu:

select your editor. I am using ubuntu, you might get something like this:
Select an editor.  To change later, run 'select-editor'.
  1. /bin/nano        <---- easiest
  2. /usr/bin/vim.tiny
  3. /bin/ed

Choose 1-3 [1]: 

Lets see what else we have heres