I am writing a script that prepares my Linux system for benchmarking. Among other things I want to stop all systemd timer units, and revert this action afterwards.

In short, I need the equivalent of service crond stop/start.

All I have found so far is systemctl list-timers and then manually stop each one, and afterwards manually start each. Do you know of any better, more generic solutions?


To stop all currently running timers, you can simply use:

systemctl stop '*.timer'

To restart the timers later, you’ll have to remember which ones were running at the time.

timers=$(systemctl list-units --type=timer --state=active --no-legend | awk '{print $1}')
systemctl stop $timers
# ...
systemctl start $timers

(Apparently patterns for units don’t match inactive units, so systemctl start '*.timer' doesn’t work.)

  • 1
    Thanks! For me the wildcard works for stopping all timers, but not for starting them.
    – jimis
    Oct 9 '18 at 15:57
  • Huh, indeed, I hadn’t tried that out. I’ve updated the answer, thanks! Oct 9 '18 at 16:03
  • This seems to be the best way currently available, so I'm accepting your answer. Thanks!
    – jimis
    Oct 12 '18 at 9:36

Good question. I don't see an option for this in man systemctl or man systemd.timer

On a relatively clean system, there are likely only a small number that might run during your benchmark. So after you run the systemctl stop commands the first the time, the next time save your stop/start commands in bash scripts, and just automate the stop/start commands that way.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.