Managing Services in Linux
Source: Dev.to
Linux commands reminder
In this lab we’ll use a number of Linux commands that were already explained during Course 3. Here is a quick reminder of what these commands do:
sudo– executes a command with administrator rightsls– lists the files in a directorymv– moves or renames a filetail– shows the last lines of a filecat– prints the whole contents of a filegrep– filters the text of a file according to a patternless– lets you browse a file
You can combine these commands using the pipe operator (|). For example:
sudo cat /var/log/syslog | grep error | tail
The command above prints the contents of /var/log/syslog, keeps only the lines that contain “error”, and then shows the last 10 lines of that filtered output.
You can always read the manual page for any command with man.
Tip: While you can copy‑paste the commands, typing them manually helps with understanding and memory.
Listing system services
To view the services installed on the machine, use the service command.
sudo service --status-all
Output example
[ - ] avahi-daemon
[ - ] cron
[ - ] cups
[ - ] cups-browsed
[ - ] dbus
[ - ] exim4
[ ? ] hwclock.sh
[ - ] procps
[ + ] rsyslog
[ - ] saned
[ + ] ssh
[ - ] sudo
[ + ] udev
Legend
+– service is active/running-– service is inactive/stopped?– unable to determine the service state
Stopping and starting services
Now that we have listed the services, let’s practice stopping and starting one of them. We’ll work with the rsyslog service, which writes system logs to files such as /var/log/syslog, /var/log/kern.log, and /var/log/auth.log.
Check service status
sudo service rsyslog status
Sample output
rsyslogd is running.
The status command shows that the service is loaded, enabled (starts automatically on boot), and currently active.
Generate a test log entry
You can see the service in action with the logger command:
logger This is a test log entry