Bird
Raised Fist0
Linux CLIscripting~20 mins

Editing crontab (crontab -e) in Linux CLI - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Crontab Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the output of this crontab entry?
Given the crontab entry below, what will be the output when it runs?

0 5 * * * echo "Backup started" >> /tmp/backup.log
AThe message "Backup started" is appended to /tmp/backup.log at 5:00 AM daily.
BThe message "Backup started" is printed on the terminal at 5:00 AM daily.
CThe message "Backup started" is overwritten in /tmp/backup.log at 5:00 AM daily.
DThe message "Backup started" is appended to /tmp/backup.log every minute.
Attempts:
2 left
💡 Hint
Remember that '>>' appends output to a file and the schedule '0 5 * * *' means 5:00 AM every day.
📝 Syntax
intermediate
2:00remaining
Which crontab entry is syntactically correct?
Select the crontab entry that will NOT cause a syntax error when saved.
A15 25 * * * /usr/bin/backup.sh
B60 12 * * * /home/user/run.sh
C30 14 * * 1-5 /usr/bin/python3 /home/user/script.py
D0 0 0 * * /usr/bin/cleanup.sh
Attempts:
2 left
💡 Hint
Minutes must be between 0-59 and hours between 0-23 in crontab.
🔧 Debug
advanced
2:00remaining
Why does this crontab entry not run the script?
A user added this line to their crontab:

0 3 * * * /home/user/myscript.sh

But the script does not run at 3 AM. What is the most likely reason?
AThe script /home/user/myscript.sh does not have execute permission.
BThe crontab entry is missing the username field.
CThe time format '0 3 * * *' is invalid.
DCrontab cannot run scripts located in /home directories.
Attempts:
2 left
💡 Hint
Check file permissions and execution rights for scripts run by cron.
🚀 Application
advanced
2:00remaining
Schedule a script to run every 15 minutes using crontab
Which crontab entry correctly runs /usr/local/bin/cleanup.sh every 15 minutes?
A0,15,30,45 * * * * /usr/local/bin/cleanup.sh
B15 * * * * /usr/local/bin/cleanup.sh
C0-15 * * * * /usr/local/bin/cleanup.sh
D*/15 * * * * /usr/local/bin/cleanup.sh
Attempts:
2 left
💡 Hint
Use the step value syntax to run commands at intervals.
🧠 Conceptual
expert
2:00remaining
What happens if you edit crontab with 'crontab -e' and save an empty file?
If a user runs 'crontab -e' and deletes all lines, saving an empty file, what is the effect on their scheduled jobs?
AThe system restores the previous crontab automatically.
BAll scheduled cron jobs for that user are removed and will no longer run.
CCron jobs continue running as before because empty file is ignored.
DAn error is shown and the empty crontab is not saved.
Attempts:
2 left
💡 Hint
Think about what an empty crontab means for scheduled tasks.

Practice

(1/5)
1. What does the command crontab -e do in Linux?
easy
A. It deletes all cron jobs for the current user.
B. It lists all scheduled cron jobs for all users.
C. It runs the cron daemon immediately.
D. It opens the current user's cron jobs for editing.

Solution

  1. Step 1: Understand the purpose of crontab -e

    This command opens the cron table for the current user in an editor so you can add or change scheduled tasks.
  2. Step 2: Compare with other options

    crontab -l lists jobs, not edits. Deleting or running the daemon are different commands.
  3. Final Answer:

    It opens the current user's cron jobs for editing. -> Option D
  4. Quick Check:

    crontab -e = edit cron jobs [OK]
Hint: Remember: '-e' means edit your cron jobs [OK]
Common Mistakes:
  • Confusing '-e' with '-l' which lists jobs
  • Thinking it deletes cron jobs
  • Assuming it runs cron immediately
2. Which of the following is the correct syntax to schedule a cron job to run every day at 3:30 AM using crontab -e?
easy
A. 30 3 * * * /path/to/script.sh
B. 3 30 * * * /path/to/script.sh
C. * 3 30 * * /path/to/script.sh
D. 30 03 * * /path/to/script.sh

Solution

  1. Step 1: Understand cron time fields order

    The order is: minute hour day-of-month month day-of-week. So 30 3 means 3:30 AM.
  2. Step 2: Check each option

    30 3 * * * /path/to/script.sh correctly uses '30 3' for 3:30 AM daily. 3 30 * * * /path/to/script.sh swaps minute and hour. * 3 30 * * /path/to/script.sh misplaces day and minute. 30 03 * * /path/to/script.sh misses a field.
  3. Final Answer:

    30 3 * * * /path/to/script.sh -> Option A
  4. Quick Check:

    Minute Hour Day Month Weekday = 30 3 * * * [OK]
Hint: Minute comes before hour in cron syntax [OK]
Common Mistakes:
  • Swapping hour and minute fields
  • Missing one of the five time fields
  • Using leading zeros incorrectly
3. After adding this line in crontab -e:
0 0 * * 0 /home/user/backup.sh
What will happen?
medium
A. The script runs every day at midnight.
B. The script runs every Sunday at midnight.
C. The script runs every hour on Sundays.
D. The script runs once a month at midnight.

Solution

  1. Step 1: Decode the cron schedule

    Fields: minute=0, hour=0, day-of-month=*, month=*, day-of-week=0. Day-of-week 0 means Sunday.
  2. Step 2: Interpret the schedule

    The script runs at 00:00 (midnight) on every Sunday.
  3. Final Answer:

    The script runs every Sunday at midnight. -> Option B
  4. Quick Check:

    0 0 * * 0 = Sunday midnight [OK]
Hint: Day-of-week 0 means Sunday in cron [OK]
Common Mistakes:
  • Thinking it runs daily instead of weekly
  • Confusing day-of-month with day-of-week
  • Assuming 0 means Monday
4. You added this line in crontab -e:
60 12 * * * /home/user/script.sh
Why does this cron job not run?
medium
A. Script path must be absolute, this is relative.
B. Hour 12 is invalid; hours range 0-11.
C. Minute value 60 is invalid; minutes range 0-59.
D. Missing day-of-week field causes error.

Solution

  1. Step 1: Check the minute field validity

    Minutes must be between 0 and 59. 60 is invalid and causes cron to ignore the job.
  2. Step 2: Verify other fields

    Hour 12 is valid (means noon). Day-of-week is optional. Script path is absolute.
  3. Final Answer:

    Minute value 60 is invalid; minutes range 0-59. -> Option C
  4. Quick Check:

    Minute must be 0-59, 60 is invalid [OK]
Hint: Minutes max at 59, not 60 [OK]
Common Mistakes:
  • Using 60 as a minute value
  • Confusing 12-hour clock with 24-hour
  • Thinking day-of-week is mandatory
5. You want to run a backup script every weekday at 11:45 PM using crontab -e. Which line correctly schedules this?
hard
A. 45 23 * * 1-5 /home/user/backup.sh
B. 23 45 * * 1-5 /home/user/backup.sh
C. 45 23 * * 0-6 /home/user/backup.sh
D. 45 11 * * 1-5 /home/user/backup.sh

Solution

  1. Step 1: Understand the time and days needed

    11:45 PM is hour 23, minute 45. Weekdays are Monday(1) to Friday(5).
  2. Step 2: Check each option's correctness

    45 23 * * 1-5 /home/user/backup.sh uses '45 23' for 11:45 PM and '1-5' for weekdays correctly. 23 45 * * 1-5 /home/user/backup.sh swaps minute and hour. 45 23 * * 0-6 /home/user/backup.sh runs every day. 45 11 * * 1-5 /home/user/backup.sh uses hour 11 (11 AM) instead of 23.
  3. Final Answer:

    45 23 * * 1-5 /home/user/backup.sh -> Option A
  4. Quick Check:

    Minute Hour Days 1-5 = 45 23 Mon-Fri [OK]
Hint: Hour 23 = 11 PM; weekdays 1-5 [OK]
Common Mistakes:
  • Swapping hour and minute fields
  • Using 11 instead of 23 for PM
  • Using 0-6 instead of 1-5 for weekdays
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard