What is a systemd timer, and how does it differ from cron?
A systemd timer is a .timer unit that starts a matching .service on a schedule or after boot. Unlike cron, its output goes to the journal, it can run missed jobs after downtime with Persistent=true, and it supports dependencies and resource limits.
Explain it simply
cron is a simple alarm clock: at 02:00, run this command. A systemd timer is a smarter alarm that is tied to a service unit and to the rest of the system.
Two files are involved:
backup.service holds the job (ExecStart=/opt/backup.sh, Type=oneshot).
backup.timer holds the schedule:
[Timer]
OnCalendar=*-*-* 02:00:00
Persistent=true
[Install]
WantedBy=timers.targetThen sudo systemctl enable --now backup.timer and check systemctl list-timers.
Advantages: logs in journalctl -u backup.service, Persistent=true runs a missed job after the machine was off, OnBootSec=10min and OnUnitActiveSec=1h give relative timing, and you can set User=, memory limits and ordering.
Cron is still shorter for quick one-liners and is available everywhere, so know both. Test a calendar expression with systemd-analyze calendar "Mon *-*-* 09:00".
Example
sudo systemctl enable --now backup.timer
systemctl list-timers --no-pager | head -3
# NEXT LEFT UNIT ACTIVATES
# Tue 2026-10-06 02:00:00 IST 15h left backup.timer backup.serviceWhat to say in the interview
"A timer unit triggers a service on a calendar or monotonic schedule. Compared with cron I get journal logging, Persistent=true for missed runs, and dependency control. I still use cron for simple quick jobs."
Common mistakes
- Creating only a .timer file without the matching .service.