Linux команды · 1 min read · Jan 10, 2026
Учебник по команде service в Linux для начинающих (с примерами)

Команда service позволяет вам запускать скрипт инициализации System V. В этом учебнике мы кратко обсудим этот инструмент, используя несколько простых примеров. Но прежде чем мы это сделаем, стоит упомянуть, что все примеры были протестированы на машине с Ubuntu 18.04 LTS.
Команда service в Linux
Вот доступный синтаксис для команды service в Linux:
service SCRIPT COMMAND [OPTIONS]
service --status-all
service --help | -h | --versionА вот как это объясняется в странице man:
service runs a System V init script or systemd unit in as predictable an environment as possible,
removing most environment variables and with the current working directory set to /.
The SCRIPT parameter specifies a System V init script, located in /etc/init.d/SCRIPT, or the name
of a systemd unit. The existence of a systemd unit of the same name as a script in /etc/init.d
will cause the unit to take precedence over the init.d script. The supported values of COMMAND
depend on the invoked script. service passes COMMAND and OPTIONS to the init script unmodified.
For systemd units, start, stop, status, and reload are passed through to their systemctl/initctl
equivalents.
All scripts should support at least the start and stop commands. As a special case, if COMMAND
is --full-restart, the script is run twice, first with the stop command, then with the start
command.
service --status-all runs all init scripts, in alphabetical order, with the status command. The
status is [ + ] for running services, [ - ] for stopped services and [ ? ] for services
without a status command. This option only calls status for sysvinit jobs.Как использовать команду service?
Использование инструмента командной строки ‘service’ совсем несложно. Давайте поговорим о том, как вы можете использовать эту утилиту для работы со скриптами, такими как httpd и sshd.
Вот как вы запускаете скрипт с помощью service:
service httpd startВот как вы останавливаете уже запущенный скрипт с помощью service:
service sshd stopВот как вы получаете статус скрипта:
service httpd statusВот как вы перезапускаете уже работающий сервис:
service sshd restartЗаключение
В зависимости от ваших привилегий как пользователя Linux, вы можете захотеть запустить все приведенные выше примеры с помощью команды ‘sudo’. Чтобы узнать больше о команде ‘service’, перейдите на ее страницу man.
Get new posts in your inbox
No spam. Unsubscribe anytime.