如何从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=

参数应该是以逗号分隔的单位LOADSUBACTIVE状态列表。 列出单位时,仅显示指定状态的单位。 使用--state=failed仅显示失败的单位。

说明:

LOAD :反映是否正确加载了单位定义。
ACTIVE :高级单元激活状态,即SUB泛化。
SUB :低级单元激活状态,值取决于单元类型。

虽然您也可以使用它来仅显示enabled单位:

 systemctl list-unit-files --state=enabled 

如果enabled了单元,则意味着系统将在启动时启动它。 虽然设置某些内容但实际上并没有start它,因此您需要手动执行此操作,或者在将其设置为enabled后重新启动系统。

  1. 列出处于state=activesub=running所有systemd服务

     systemctl list-units --type=service --state=running 
  2. 列出所有处于state=active和sub运行或退出的systemd serice

     systemctl list-units --type=service --state=active 

希望这能解决问题。

要查看“已启用”服务,包括仍在upstart / init运行的服务:

 systemctl list-unit-files --type service --state enabled,generated 

要查看所有当前正在运行的服务:

 systemctl list-units --type service --state running