如何从systemctl列出所有已启用的服务?
如何列出systemctl
中所有已enabled
服务?
我知道systemctl
列出了所有服务,但我想只获得enabled
的服务。
systemctl list-unit-files | grep enabled
systemctl list-unit-files | grep enabled
将列出所有已启用的。
如果您想要当前正在运行哪些,则需要systemctl | grep running
systemctl | grep running
。
使用你正在寻找的那个。 启用,并不意味着它正在运行。 并且运行并不意味着它已启用。 他们是两个不同的东西。
启用表示系统将在下次启动时运行该服务。 因此,如果启用服务,您仍需要手动启动它,或重新启动它,它将启动。
运行意味着它实际上正在运行,但是如果它未启用,则在重新启动时不会重新启动。
man systemctl
说:
--state=
参数应该是以逗号分隔的单位
LOAD
,SUB
或ACTIVE
状态列表。 列出单位时,仅显示指定状态的单位。 使用--state=failed
仅显示失败的单位。
说明:
LOAD
:反映是否正确加载了单位定义。
ACTIVE
:高级单元激活状态,即SUB
泛化。
SUB
:低级单元激活状态,值取决于单元类型。
虽然您也可以使用它来仅显示enabled
单位:
systemctl list-unit-files --state=enabled
如果enabled
了单元,则意味着系统将在启动时启动它。 虽然设置某些内容但实际上并没有start
它,因此您需要手动执行此操作,或者在将其设置为enabled
后重新启动系统。
-
列出处于
state=active
和sub=running
所有systemd
服务systemctl list-units --type=service --state=running
-
列出所有处于
state=active
和sub运行或退出的systemd
sericesystemctl list-units --type=service --state=active
希望这能解决问题。
要查看“已启用”服务,包括仍在upstart / init运行的服务:
systemctl list-unit-files --type service --state enabled,generated
要查看所有当前正在运行的服务:
systemctl list-units --type service --state running