The crontab is a built-in Linux scheduling tool that lets you run commands and scripts automatically at any time or interval without any manual interaction. It works on top of the crond daemon, which runs continuously in the background and checks every minute whether any scheduled jobs are due to execute. System administrators use crontab to automate routine tasks like backups, log rotation, disk cleanup, and remote syncing.

This guide covers the crontab syntax for Debian 12, provides 12 practical examples from running scripts at midnight to backing up directories on a weekly schedule, and explains how to list, create, and remove cron jobs for any user. Many system-level cron jobs require sudo access on Debian 12 to execute correctly.

Quick Answer

Open the crontab editor with:

crontab -e

Add a line using this format, then save with Ctrl + S and exit with Ctrl + X:

[Minute] [Hour] [Day of month] [Month] [Day of week] /path/to/script.sh

Use * as a wildcard for any value. For example, 0 3 * * * /backup.sh runs the script every day at 3 AM.

Understanding the crontab Syntax

The crontab file stores scheduled jobs, one per line. Open it with crontab -e, which creates it if no file exists yet for the current user:

crontab -e
Debian crontab file open in editor after running crontab -e showing the default template with comment lines

Each line follows this format:

[Minute] [Hour] [Day (of the month)] [Month (of the year)] [Day (of the week)] [path_to_script_or_command]

The five time fields accept numbers, ranges like 1-5, comma-separated lists like 1,3,5, step values like */5, or * as a wildcard meaning every unit. All configurations are stored in /tmp/crontab.random/crontab for the current user.

How to Use Debian crontab

Example 1: Save the Date and Time on Every Reboot

Use the @reboot shortcut to run a command each time the system boots. This example appends the current date and time to a file called date.txt in the home directory:

@reboot date >> ~/date.txt
Crontab file showing @reboot date data-lazy-src=