用 systemctl cat/edit 查看和覆盖服务单元
systemctl cat 会显示服务单元文件及所有 drop-in 覆盖;systemctl edit 可以不碰官方文件地创建覆盖配置。
运行 `systemctl cat <服务名>.service` 查看单元及覆盖,`sudo systemctl edit <服务名>` 创建覆盖配置。
01命令
命令
$ systemctl cat nginx.service02作用说明
容易被忽略的点:/etc/systemd/system/<unit>.d/*.conf 里的 drop-in 片段会叠加或替换官方设置,所以实际运行的配置可能与 /lib/systemd/system 里的不一样。`systemctl edit` 会自动打开覆盖模板并在保存后执行 daemon-reload。想撤销所有本地修改、恢复出厂配置,用 `sudo systemctl revert <unit>`。
03风险
!注意: 修改覆盖文件可能导致服务无法启动,改完务必检查 systemctl status。
04撤销
撤销
$ sudo systemctl revert nginx.service && sudo systemctl daemon-reload05来源
- systemctl(1) - Linux manual page依据: systemctl cat shows the unit file including any drop-ins; systemctl edit creates an override; systemctl revert restores the vendor version.
最后验证: 2026-09-17 · 分类: 系统与设置