Linux查看开机自启动的服务
要查看系统中设置为 开机自启动 的服务,可以使用 systemctl 命令。以下是具体的方法:
1. 查看所有已启用(开机自启动)的服务
systemctl list-unit-files --type=service --state=enabled
• 这会列出所有已启用(enabled)的服务,即开机时会自动启动的服务。
• 输出示例:
UNIT FILE STATE
cron.service enabled
docker.service enabled
nginx.service enabled
ssh.service enabled
2. 查看所有已启用(开机自启动)的服务(简洁版)
systemctl list-unit-files --type=service | grep enabled
• 这会过滤出所有状态为 enabled 的服务。
3. 查看某个服务是否已启用
systemctl is-enabled <service-name>
• 例如,检查 nginx 服务是否已启用:
systemctl is-enabled nginx
• 输出可能是 enabled(已启用)、disabled(未启用)或 static(静态,无法直接启用)。
4. 查看所有服务及其启用状态
systemctl list-unit-files --type=service
• 这会列出所有服务及其状态(enabled、disabled、static 等)。
• 你可以从中筛选出 enabled 的服务。
5. 查看所有已启用的服务(包含描述信息)
systemctl list-units --type=service --state=enabled
• 这会列出所有已启用的服务,并显示服务的状态和描述信息。
6. 查看所有已启用的服务(按状态分类)
systemctl list-unit-files --type=service --state=enabled,disabled,static
• 这会列出所有服务的状态,方便你查看哪些服务是 enabled(开机自启动)。
7. 查看所有已启用的服务(按优先级排序)
systemctl list-unit-files --type=service --state=enabled | sort
• 这会按字母顺序排序显示所有已启用的服务。
8. 查看某个服务的依赖关系(是否被其他服务依赖)
systemctl list-dependencies <service-name>
• 例如,查看 nginx 服务的依赖关系:
systemctl list-dependencies nginx
总结
• 开机自启动的服务 是指状态为 enabled 的服务。
• 使用 systemctl list-unit-files --type=service --state=enabled 可以快速查看所有开机自启动的服务。
• 如果需要更详细的信息,可以结合 systemctl list-units 或 systemctl is-enabled 命令。
通过这些命令,你可以轻松管理系统的开机自启动服务。

