> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# SystemD Timers

> Explains how to use systemd timers to schedule and manage recurring or one-time tasks, including unit locations, commands, drop-in overrides, and examples.

You can schedule one-time jobs with `at` and recurring jobs with `cron`. In this article we cover a more modern, integrated approach using systemd timers — the systemd-native way to schedule tasks.

systemd timers schedule jobs using the same framework that manages services on Linux. Compared with traditional cron jobs, timers offer improved logging, dependency control, integration with service units, and awareness of system state (boots, shutdowns, targets). Because timers are first-class systemd units, they participate in restart policies and the systemd journal, making them more flexible and reliable for many automation use cases.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/9E2T0ocsNwD7Od8i/images/Prep-Course-Red-Hat-Certified-System-Administrator-RHCSA/Scheduling-Future-Tasks/SystemD-Timers/why-use-systemd-timers-benefits-slide.jpg?fit=max&auto=format&n=9E2T0ocsNwD7Od8i&q=85&s=ad41ed6e6a3d42e9752a74d6ca2894a4" alt="A dark-themed presentation slide titled &#x22;Why Use Systemd Timers?&#x22; that lists three numbered benefits: built directly into systemd, triggers systemd service units, and integrates with the system journal, each with brief explanatory text. Each item is shown with a circular number icon and horizontal accent lines." width="1920" height="1080" data-path="images/Prep-Course-Red-Hat-Certified-System-Administrator-RHCSA/Scheduling-Future-Tasks/SystemD-Timers/why-use-systemd-timers-benefits-slide.jpg" />
</Frame>

Think of a systemd timer as an alarm clock; the corresponding service unit is the action performed when the alarm goes off.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/9E2T0ocsNwD7Od8i/images/Prep-Course-Red-Hat-Certified-System-Administrator-RHCSA/Scheduling-Future-Tasks/SystemD-Timers/systemd-timers-alarm-clock-service-action.jpg?fit=max&auto=format&n=9E2T0ocsNwD7Od8i&q=85&s=38cfc526bd2e85b552e138410e6e189f" alt="A dark-themed slide titled &#x22;SystemD Timers&#x22; that says &#x22;Think of them as alarm clocks,&#x22; with a blue outline alarm-clock icon in the center. Below it is a line explaining that the service is the action performed when the alarm goes off." width="1920" height="1080" data-path="images/Prep-Course-Red-Hat-Certified-System-Administrator-RHCSA/Scheduling-Future-Tasks/SystemD-Timers/systemd-timers-alarm-clock-service-action.jpg" />
</Frame>

A systemd timer always works together with a service unit:

* The `.timer` file defines *when* something runs.
* The `.service` file defines *what* runs.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/9E2T0ocsNwD7Od8i/images/Prep-Course-Red-Hat-Certified-System-Administrator-RHCSA/Scheduling-Future-Tasks/SystemD-Timers/systemd-timers-vs-service-units.jpg?fit=max&auto=format&n=9E2T0ocsNwD7Od8i&q=85&s=6e3d7bf91485a7f1e6fc0a7d504f7f63" alt="A dark presentation slide titled &#x22;SystemD Timers&#x22; showing two file icons: one labeled &#x22;.timer&#x22; with a clock and the caption &#x22;Defines when something runs,&#x22; and one labeled &#x22;.service&#x22; with a gear. The graphic contrasts timer and service unit files." width="1920" height="1080" data-path="images/Prep-Course-Red-Hat-Certified-System-Administrator-RHCSA/Scheduling-Future-Tasks/SystemD-Timers/systemd-timers-vs-service-units.jpg" />
</Frame>

Key behavior:

* When a `.timer` reaches its scheduled time, systemd activates the associated `.service`.
* Timers can be relative (e.g., `OnActiveSec`), absolute (`OnCalendar`), or tied to boot/shutdown events.
* Timers integrate with systemd targets and the systemd journal for consistent logging and control.

## Where timer units live

Timer unit files can be created or provided by different sources. Use this table to choose the correct location and editing approach.

| Location | Purpose | Notes / Example |
| - | - | - |
| `/usr/lib/systemd/system` | Distribution/vendor-provided units | Package-managed; do **not** edit directly. |
| `/etc/systemd/system` | System administrator-supplied or modified units | Use to place full custom units or overrides copied from vendor. |
| `~/.config/systemd/user` | Per-user timers and services | User-level units; managed with `--user` for `systemctl`. |

## Quick commands

* List active timers and their next run times:
  * `systemctl list-timers`
* Inspect the combined unit contents (vendor file + overrides):
  * `systemctl cat <timer-name>`
* Create or edit a drop-in override:
  * `systemctl edit <unit>`
* Reload systemd configuration:
  * `systemctl daemon-reload`
* Restart or check a unit:
  * `systemctl restart <unit>`
  * `systemctl status <unit>`

Example: list timers output and inspecting a timer (these are sample outputs to illustrate the commands):

```bash theme={null}
# List active timers and next runtimes
root@control:~# systemctl list-timers
NEXT                           LEFT   LAST                         PASSED UNIT                        ACTIVATES
Wed 2026-04-22 13:48:32 EEST    44s   Wed 2026-04-22 12:22:37 EEST  1h 25min ago dnf-makecache.timer           dnf-makecache.service
Wed 2026-04-22 14:41:47 EEST    53min Wed 2026-04-22 13:47:36 EEST  11s ago     fwupd-refresh.timer           fwupd-refresh.service
Thu 2026-04-23 00:08:42 EEST    10h   Wed 2026-04-22 12:04:36 EEST  1h 43min ago logrotate.timer               logrotate.service
Thu 2026-04-23 00:25:11 EEST    10h   Wed 2026-04-22 11:02:53 EEST     -         plocate-updatedb.timer       plocate-updatedb.service
Thu 2026-04-23 11:52:37 EEST    22h   Wed 2026-04-22 11:52:37 EEST  1h 55min ago systemd-tmpfiles-clean.timer  systemd-tmpfiles-clean.service
Sun 2026-04-26 01:00:00 EEST    3 days Mon 2026-04-20 14:48:29 EEST     -         raid-check.timer             raid-check.service
Mon 2026-04-27 00:30:24 EEST    4 days Mon 2026-04-20 16:02:12 EEST     -         fstrim.timer                 fstrim.service

7 timers listed.
Pass --all to see loaded but inactive timers, too.
```

Inspecting the `logrotate.timer` combined (vendor file + overrides):

```bash theme={null}
# Show combined contents of the timer unit (vendor file + any drop-ins)
root@control:~# systemctl cat logrotate.timer
# /usr/lib/systemd/system/logrotate.timer
[Unit]
Description=Daily rotation of log files
Documentation=man:logrotate(8) man:logrotate.conf(5)

[Timer]
OnCalendar=daily
RandomizedDelaySec=1h
Persistent=true

[Install]
WantedBy=timers.target
```

## Editing vendor-provided timers: drop-in overrides (recommended)

Vendor files (under `/usr/lib/systemd/system`) may be replaced by package updates. To customize safely, do one of the following:

* Copy the vendor unit to `/etc/systemd/system` and edit the copy — this creates a full local unit.
* Prefer creating a drop-in override using `systemctl edit <unit>` — this preserves the vendor unit and applies only your changes.

<Callout icon="lightbulb" color="#1CB2FE">
  Use `systemctl edit <unit>` to create a drop-in override file under `/etc/systemd/system/<unit>.d/`. This preserves the vendor file and keeps your customizations separate and upgrade-safe.
</Callout>

Behavior of drop-ins:

* Drop-in files live in `/etc/systemd/system/<unit>.d/` and are merged on top of vendor files.
* To replace an existing directive from the vendor file, first clear it by assigning an empty value, then add the new value.

Example: create an override to schedule `logrotate.timer` to run once on 2026-05-01 at 10:00:00.

Contents of the created override file (`/etc/systemd/system/logrotate.timer.d/override.conf`):

```ini theme={null}
### Editing /etc/systemd/system/logrotate.timer.d/override.conf
### Anything between here and the comment below will become the contents of the drop-in file
[Timer]
OnCalendar=
OnCalendar=2026-05-01 10:00:00

### Edits below this comment will be discarded

### /usr/lib/systemd/system/logrotate.timer
# [Unit]
# Description=Daily rotation of log files
# Documentation=man:logrotate(8) man:logrotate.conf(5)
#
# [Timer]
# OnCalendar=daily
# RandomizedDelaySec=1h
# Persistent=true
#
# [Install]
# WantedBy=timers.target
```

After saving the drop-in, `systemctl` acknowledges the installation and you can verify the effective configuration with `systemctl cat`:

```bash theme={null}
root@control:/etc/systemd/system# systemctl edit logrotate.timer
Successfully installed edited file '/etc/systemd/system/logrotate.timer.d/override.conf'.
root@control:/etc/systemd/system# systemctl cat logrotate.timer
[Unit]
Description=Daily rotation of log files
Documentation=man:logrotate(8) man:logrotate.conf(5)

[Timer]
OnCalendar=daily
RandomizedDelaySec=1h
Persistent=true

[Install]
WantedBy=timers.target

# /etc/systemd/system/logrotate.timer.d/override.conf
[Timer]
OnCalendar=
OnCalendar=2026-05-01 10:00:00
```

Reload systemd and restart the timer so it picks up the new schedule:

```bash theme={null}
# Reload unit files and restart the timer
root@control:~# systemctl daemon-reload
root@control:~# systemctl restart logrotate.timer
root@control:~# systemctl status logrotate.timer
```

This ensures systemd will activate the associated `logrotate.service` at the updated time.

## Summary

* systemd timers are the preferred, systemd-native replacement or complement to `cron` where you need improved logging, dependency handling, and integration with system state.
* Always prefer drop-in overrides (via `systemctl edit`) to preserve vendor files and ensure updates don’t overwrite your changes.
* Use `systemctl list-timers` and `systemctl cat` to inspect timer schedules and effective unit configurations.

Further reading and references:

* systemd.time — OnCalendar and time specifications: [https://www.freedesktop.org/software/systemd/man/systemd.time.html](https://www.freedesktop.org/software/systemd/man/systemd.time.html)
* systemd.unit and systemd.timer manual pages: [https://www.freedesktop.org/software/systemd/man/systemd.timer.html](https://www.freedesktop.org/software/systemd/man/systemd.timer.html)
* systemctl(1) documentation: [https://www.freedesktop.org/software/systemd/man/systemctl.html](https://www.freedesktop.org/software/systemd/man/systemctl.html)

This concludes the demo on managing systemd timers.

<CardGroup>
  <Card title="Watch Video" icon="video" cta="Learn more" href="https://learn.kodekloud.com/user/courses/red-hat-certified-system-administrator-rhcsa/module/47c5bb98-697d-4682-97b5-abdeb8a3f704/lesson/9d5486dd-f1cb-457e-b8c6-48068a7e6db8" />
</CardGroup>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.