Ilias95 Ilias95 - 11 months ago 42
Linux Question

systemd - how to list all masked units

Is there any 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) }'

Any clearer way?


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