How do I list all systemd masked units?

14.4k views Asked by At

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?

2

There are 2 answers

0
nando On BEST ANSWER

The --state option would do the job

systemctl list-unit-files --state=masked
0
larsks On

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}'