Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I list all systemd masked units?

Tags:

linux

systemd

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?

like image 692
ilstam Avatar asked Jun 11 '15 13:06

ilstam


People also ask

How do you list units in Systemctl?

To show all installed unit files use 'systemctl list-unit-files'. The header and the last unit of a given type are underlined if the terminal supports that. A colored dot is shown next to services which were masked, not found, or otherwise failed.

How can you tell if a service is masked?

This will be displayed if you check e.g. by systemctl status service_name. systemctl list-unit-files is listing the state of the unit files (static, enabled, disabled, masked, indirect) , you can list all services which are masked, enabled or disabled.

What would you type to list all systemd service unit files?

To see a list of all of the active units that systemd knows about, we can use the list-units command: systemctl list-units.

How do I unmask a service in Linux?

Use the systemctl unmask command to unmask the service unit. [root@host ~]# systemctl unmask sendmail Removed /etc/systemd/system/sendmail. service. Note: A disabled service can be started manually or by other unit files but it does not start automatically at boot.


2 Answers

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}'
like image 156
larsks Avatar answered Nov 03 '22 10:11

larsks


The --state option would do the job

systemctl list-unit-files --state=masked
like image 22
nando Avatar answered Nov 03 '22 10:11

nando