18

Is there an easy way to list all systemd masked units?

I can think of:

ls -l /etc/systemd/system/* | grep /dev/null

Or (for unit names only):

ls -l /etc/systemd/system/* | grep /dev/null | cut -d' ' -f12 | awk -F'/' '{ print $(NF) }'

Is there a clearer way?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
ilstam
  • 1,473
  • 4
  • 18
  • 32
  • 1
    You would also need to look in `/run/systemd/system`, which is where "runtime" configuration lives (that is, configuration that will not persist after a reboot). – larsks Jun 11 '15 at 14:54

2 Answers2

29

The --state option would do the job

systemctl list-unit-files --state=masked
nando
  • 501
  • 5
  • 6
11

I think the best way of getting this information might be:

systemctl list-unit-files | grep masked

Or, for just unit names:

systemctl list-unit-files | awk '/masked/ {print $1}'

Of course, either of those expressions would actually match units that contained "masked" in the name. More accurate would be:

systemctl list-unit-files | awk '$2 == "masked" {print $1}'
larsks
  • 277,717
  • 41
  • 399
  • 399