19 October 2026 · One command a day
How do I schedule a task to run on a timer on Linux with crontab?
crontab -e opens your personal schedule of timed jobs in a text editor. Each line you add tells cron to run a command at a set minute, hour, day or month. You reach for it when something needs to happen on a schedule, such as a nightly backup or a weekly clean-up.
I learn my automation tips in the AI Profit Boardroom. Have a look here. Affiliate link.
The command
crontab -e
crontab manages the cron table for the current user, and -e means edit. Run it as yourself to schedule jobs that run as your user. Run sudo crontab -e to edit root's table, for jobs that need root. Inside the file, each job is one line with five time fields and then the command. A typical line looks like this:
30 2 * * * /home/user/backup.sh >> /home/user/backup.log 2>&1
The fields are minute (0 to 59), hour (0 to 23), day of the month (1 to 31), month (1 to 12) and day of the week (0 to 7, where 0 and 7 are both Sunday). An asterisk means every value. So this line runs at 02:30 every day. The >> /home/user/backup.log 2>&1 part appends normal output and errors to a log file, so you can see what happened.
What you will see
no crontab for user - using an empty one
Select an editor. To change later, run 'select-editor'.
1. /bin/nano <---- easiest
2. /usr/bin/vim.basic
3. /usr/bin/vim.tiny
4. /bin/ed
Choose 1-4 [1]: 1
crontab: installing new crontab
The first time you run it, there is no crontab yet, so Ubuntu asks which editor to use. Pick nano if you are unsure. The file opens with comment lines starting with #. Add your job on a new line at the bottom, then save and exit. In nano that is Ctrl+O, Enter, then Ctrl+X. The message crontab: installing new crontab means cron accepted the file. If there is a syntax error, it tells you and offers to reopen the editor.
When to use it
- Running a database or files backup script every night at a quiet hour.
- Clearing out old logs once a week, for example with the command in how to delete log files older than 30 days.
- Calling a URL on a timer, such as
*/15 * * * * curl -fsS https://example.com/cron > /dev/nullto trigger an app's scheduled tasks every 15 minutes.
Watch out for
Cron runs jobs with a very small environment. The PATH is usually just /usr/bin:/bin, and your shell profile is not loaded. A command that works in your terminal, such as node or pm2 installed under your home directory, can fail silently under cron. Use full paths to every program and file, which you can find with which node. Also, a % sign in a cron line is treated as a newline, so escape it as \%, for example in date +\%F.
Questions people ask
How do I see my cron jobs without editing them?
Run crontab -l to print your table, or sudo crontab -l for root's. It is read-only, so you cannot break anything by accident.
How do I check that a cron job actually ran?
Run journalctl -u cron --since today to see each time cron started a job. For the job's own output, check the log file you redirected it to, as explained in how to read a service's logs for the last hour.
Scheduling your own jobs at the system level is the kind of thing you can only do on a server you control. You can get the same VPS with 20% off at https://asksteves.co.uk/vps. Affiliate link.
Want more automation tips? The AI Profit Boardroom on Skool is where I get mine. Have a look here. Affiliate link.
Everything on this blog runs on one Hostinger KVM 8. This link takes 20% off the same box.
Affiliate link.