如何列出Ubuntu Server /桌面中的服务
时间:2020-07-27 12:59:37 来源:igfitidea点击:
在本教程中,我们将学习如何使用命令行界面列出Ubuntu中的服务。
我们将看到我们如何列出未运行的运行服务和服务。
使用service命令列出Ubuntu服务
service --status-all命令将列出ubuntu服务器上的所有服务(运行服务和不运行服务)。
service --status-all
这将显示Ubuntu系统上的所有可用服务。
运行服务的状态为[+],用于停止服务。
使用Grep命令,我们可以过滤输出以仅显示运行服务。
service --status-all | grep '\[ + \]'
列出未运行的Ubuntu服务,键入,
service --status-all | grep '\[ - \]'
服务命令可用于列出所有Ubuntu版本中的服务,包括(Ubuntu 17,16.04和14.04)。
使用systemctl命令列出服务
自Ubuntu 15以来,服务由Systemd管理。
使用systemd,我们可以使用systemctl命令获取有关Ubuntu系统中运行服务的信息。
要列出ubuntu上的所有运行服务,执行:
systemctl list-units
命令的输出将看起来像这样:
UNIT LOAD ACTIVE SUB DESCRIPTION apache2.service loaded active running LSB: Apache2 web server apparmor.service loaded active exited LSB: AppArmor initialization cron.service loaded active running Regular networking.service loaded active exited Raise network interfaces nmbd.service loaded active running LSB: start Samba NetBIOS nameserver (nmbd) smbd.service loaded active running LSB: start Samba SMB/CIFS daemon (smbd) ssh.service loaded active running OpenBSD LOAD = Reflects whether the unit definition was properly loaded. ACTIVE = The high-level unit activation state, for example:generalization of SUB. SUB = The low-level unit activation state, values depend on unit type.
要列出所有服务,包括非活动单元,执行:
systemctl list-units -a
要列出非活动单元,执行:
systemctl list-units -a --state=inactive
SystemCtl命令不适用于Ubuntu 14.04和早期版本,而是使用上面提到的Service --Status-all命令。