列出所有活动运行/退出/死亡的服务

“systemctl命令”可用于列出所有活动运行的服务:

$ systemctl list-units --all --type=service --no-pager | grep running

显示所有退出的服务:

$ systemctl list-units --all --type=service --no-pager | grep exited

显示所有停止/死亡的系统服务:

$ systemctl list-units --all --type=service --no-pager | grep dead

我们还可以使用“systemctl”命令启动和停止服务。

例如,要启动Apache2服务,我们可以执行:

$ systemctl start apache2

停止服务执行:

$ systemctl stop apache2

列表启用/禁用Systemd服务单元文件状态

以下systemctl命令将列出ubuntu 20.04桌面/服务器上的所有已启用的服务。

$ systemctl list-unit-files | grep enabled

列出所有禁用的服务:

$ systemctl list-unit-files | grep disabled

使用systemctl命令将服务状态设置为已启用或者禁用。

例如,以下命令将启用Apache2服务在系统引导启动期间启动:

$ sudo systemctl enable apache2

或者禁用服务在系统引导启动时启动:

$ sudo systemctl disable apache2

列出所有服务

列出所有服务单元文件:

$ systemctl list-units --all --type=service --no-pager

列出所有可用的系统单元文件:

$ systemctl list-unit-files --no-pager

可以使用grep过滤我们想要的服务单元文件:

$ systemctl list-unit-files --no-pager | grep apache2
列出Ubuntu 20.04中所有服务
日期:2020-07-07 20:55:53 来源:oir作者:oir