Based on the Linux Master 1 exam syllabusReport an error
* (all), , (list), - (range), / (step). If you specify both day and weekday, they work as OR, not AND./etc/crontab, /etc/cron.d/) has 6 fields with a user field added.cron.allow exists, only that list is allowed and cron.deny is ignored.crond wakes up every minute, checks every user's schedule list, and runs the jobs whose time has come.crontab.| Command | Action |
|---|---|
crontab -e | Edit my crontab (created if it doesn't exist) |
crontab -l | Print my crontab list |
crontab -r | Delete my entire crontab |
crontab -u user -e | Edit a specific user's crontab (root) |
crontab -e # add/modify my scheduled jobs in an editor
crontab -l # view the currently registered scheduled jobs
crontab -r # delete all scheduled jobs (careful!)
crontab -u alice -l # view alice's scheduled jobs (root privilege)⚠️ Trap:
crontab -rdeletes everything without confirmation. If you mistakenly hit-r, one key away from the-eyou meant to press, all your schedules vanish. In practice, the habit of backing up first withcrontab -l > backup.txtis recommended. You must clearly distinguish-l(list),-e(edit), and-r(delete).
┌───────────── minute (0-59)
│ ┌─────────── hour (0-23)
│ │ ┌───────── day (1-31)
│ │ │ ┌─────── month (1-12)
│ │ │ │ ┌───── weekday (0-7, both 0 and 7 are Sunday)
│ │ │ │ │
* * * * * command_to_run
| Position | Field | Range | Notes |
|---|---|---|---|
| 1 | minute | 0-59 | |
| 2 | hour | 0-23 | 24-hour clock |
| 3 | day of month | 1-31 | |
| 4 | month | 1-12 | jan-dec also allowed |
| 5 | day of week | 0-7 | 0 and 7 = Sunday, 1=Mon … 6=Sat |
| Symbol | Meaning | Example |
|---|---|---|
* | Every value | * * * * * = every minute |
, | List | 0,30 = minutes 0 and 30 |
- | Range | 1-5 = 1 to 5 |
/ | Step (interval) | */10 = every 10 |
# min hour day month weekday command
0 3 * * * /backup.sh # every day at 3:00 a.m.
30 2 * * 1 /weekly.sh # every Monday at 2:30 a.m.
0 */6 * * * /check.sh # every 6 hours (at 0, 6, 12, 18)
*/10 * * * * /poll.sh # every 10 minutes
0 0 1 * * /monthly.sh # midnight on the 1st of every month
0 9 * * 1-5 /workday.sh # 9:00 a.m. on weekdays (Mon-Fri)
15 14 1 * * /report.sh # 14:15 on the 1st of every monthThe order of the 5 fields is "minute-hour-day-month-weekday", from the smaller time unit to the larger (the weekday alone is the exception, placed last). The weekday starts with 0=Sunday and goes to 6=Saturday, and 7 is also accepted as Sunday. Since it is the 24-hour clock, 2 p.m. is 14. Memorize this order with the mnemonic "min-hour-day-month-weekday".
⚠️ Trap: If you specify both the day (3rd) and the weekday (5th), they work as OR — the job runs if either one matches. For example,
0 0 13 * 5runs "on the 13th of every month or every Friday" (not only on a Friday that is also the 13th), and it is not AND. This OR behavior easily becomes a trap.
Try it yourself: Use crontab -e to put in the single line */2 * * * * date >> ~/crontest.log and save. The current time accumulates in the file every 2 minutes. After a few minutes, check the accumulation with cat ~/crontest.log, and when you're done, delete that line in crontab -e. You get to see how the 5 fields actually run.
crontab -e), there are places for system-wide schedules — the /etc/crontab file and the /etc/cron.d/ directory.# /etc/crontab format (6 fields = 5 time fields + user + command)
# min hour day month weekday user command
0 4 * * * root /usr/local/bin/cleanup.sh
| Item | User crontab | System crontab (/etc/crontab) |
|---|---|---|
| How to create | crontab -e | Edit the file directly |
| Number of fields | 5 fields + command | 5 fields + user + command |
| Run privilege | The user who registered it | The specified user field |
| Storage location | /var/spool/cron/username | /etc/crontab, /etc/cron.d/* |
| Directory | Run interval |
|---|---|
/etc/cron.hourly/ | Every hour |
/etc/cron.daily/ | Every day |
/etc/cron.weekly/ | Every week |
/etc/cron.monthly/ | Every month |
The difference that a user crontab has 5 fields and a system crontab (/etc/crontab, cron.d) has 6 fields (user added) is a key exam point. /etc/cron.d/ is a good place for packages to add their own schedules, and it uses the same 6-field format as /etc/crontab. Directories like cron.daily take scripts without a time (the run time is managed by anacron/the system).
The word cron comes from the Greek 'chronos' (time). It has existed since 1970s Unix, and anacron was added for systems that aren't always on, like laptops — cron skips a job if the machine is off at that exact time, but anacron runs it "even right after power-on if N days have passed since the last run". This is why cron.daily and the like are tied to anacron.
| File | Meaning |
|---|---|
/etc/cron.allow | Only the users listed here can use cron (whitelist) |
/etc/cron.deny | Only the users listed here cannot use cron (blacklist) |
cron.allow exists, only that list is allowed and cron.deny is ignored.cron.allow does not exist and only cron.deny does, everyone except the deny list is allowed.The priority is allow > deny. The moment an allow file exists it becomes the only criterion and deny loses effect. at is controlled in the same way by /etc/at.allow and /etc/at.deny.
at is "exactly once". It runs a command once at the specified time and then disappears from the queue.at 17:00 # input mode for a command to run at 5 p.m.
at> /usr/local/bin/report.sh
at> <end input with Ctrl+D>
at now + 2 hours # 2 hours from now
at 10:30 tomorrow # 10:30 a.m. tomorrow
at midnight # midnight today
echo "/backup.sh" | at 3am # pass the command via a pipe| Command | Action |
|---|---|
at time | Register a job to run at that time |
atq (or at -l) | List of pending at jobs |
atrm number (or at -d) | Delete a pending job |
batch is a variant of at. It doesn't specify a time and runs automatically when the system load (load average) drops (usually below 0.8).batch # runs when the system becomes idle
at> /heavy-compute.sh
at> <Ctrl+D>| Category | cron | at | batch |
|---|---|---|---|
| Run count | Recurring | Once | Once |
| When it runs | Fixed interval | Specified time | When load is low |
| Daemon | crond | atd | atd |
| Registration | crontab -e | at time | batch |
cron is recurring, at/batch are one-time. "Back up every day at dawn" is cron, "one-time inspection tomorrow" is at. at ends its input with Ctrl+D (EOF), the list of registered jobs is atq, and deletion is atrm (at -l/at -d work the same). The difference from at is that batch runs based on load rather than time.
Try it yourself: Run echo "echo hello > ~/at-test.txt" | at now + 1 minute and check the pending list with atq. If cat ~/at-test.txt shows hello a minute later, it worked, and the job disappears from atq (confirming it is one-time). To cancel, look up the number with atq and run atrm number.
-e (edit), -l (list), -r (delete all, no confirmation)./) : The interval symbol. */10 means "every 10"./etc/crontab and /etc/cron.d/*. An execution user field follows the 5 time fields, making 6 fields./etc/cron.daily/ etc. : Directories where, if you just put a script with no time, it runs at that interval.atq, delete with atrm.Click a choice to reveal the answer and explanation.
Question 1
Which of the following lists the 5 time fields of a crontab correctly from left to right?
Question 2
When does the crontab entry 30 2 * * 1 /backup.sh run?
Question 3
Which values in the crontab weekday field both represent Sunday?
Question 4
What is the run interval of a job scheduled with */15 * * * *?
Question 5
What is the biggest format difference between a user crontab (crontab -e) and a system crontab (/etc/crontab)?
Question 6
Which of the following is correct about the priority of the cron access control files /etc/cron.allow and /etc/cron.deny?
Question 7
Which of the following is correct about the differences between cron, at, and batch?