首頁·終端機命令

service

行程與系統

用法

service <name> <start|stop|restart|status>

這是 SysV 時代留下的一層薄殼;在 systemd 機器上它只是把命令轉給 systemctl,而且認得的動詞更少。

常用選項

選項含義
start / stop / restartThe three verbs that work everywhere.
statusAsk the service how it is doing.
--status-allList every init script and its state (Debian/Ubuntu).

範例

sudo service nginx restart

Restart a service on a machine of any vintage.

service --status-all

See every service the old init system knows about.

看什麼在跑、什麼在吃機器。先弄清是什麼,再決定殺不殺。

怎麼看

  • 方括號 [ ] 表示這部分可以不寫。
  • 省略號 … 表示可以寫多個。
  • 選項區分大小寫——有些命令裡 -r 和 -R 不是一回事。

常見問題

Q. service 是做什麼的?

這是 SysV 時代留下的一層薄殼;在 systemd 機器上它只是把命令轉給 systemctl,而且認得的動詞更少。

Q. 怎麼寫?

service <name> <start|stop|restart|status> —— 方括號表示可以省略的部分。

Q. 值得記的選項有幾個?

這裡列了 3 個,完整列表在 man service。這條命令屬於行程與系統。

相關命令

man 手冊: man service