systemctl 速记手册

基本操作

启动服务

systemctl start service_name

停止服务

systemctl stop service_name

重启服务

systemctl restart service_name

重新加载服务配置

systemctl reload service_name

查看服务状态

systemctl status service_name

服务管理

启用服务(开机自启)

systemctl enable service_name

禁用服务(取消开机自启)

systemctl disable service_name

检查服务是否已启用

systemctl is-enabled service_name

查看所有已启用的服务

systemctl list-unit-files --state=enabled

系统管理

重启系统

systemctl reboot

关闭系统

systemctl poweroff

待机

systemctl suspend

休眠

systemctl hibernate

查看系统信息

查看系统启动时间

systemctl list-dependencies

查看系统启动耗时

systemctl list-dependencies --reverse

查看所有失败的服务

systemctl --failed

查看所有正在运行的服务

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

日志管理

查看服务日志

journalctl -u service_name

实时查看服务日志

journalctl -u service_name -f

查看指定时间段的日志

journalctl -u service_name --since "2023-01-01" --until "2023-01-02"

高级操作

编辑服务单元文件

systemctl edit service_name

重新加载 systemd 配置

systemctl daemon-reload

查看服务依赖关系

systemctl list-dependencies service_name

屏蔽服务(彻底禁用)

systemctl mask service_name

取消屏蔽服务

systemctl unmask service_name

请注意,某些命令可能需要 root 权限或使用 sudo 来执行。

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容