Linux commands reminder
In this lab, we'll use a number of Linux commands that were already explained during Course 3. Here is a reminder of what these commands do:
-
sudo: executes a command with administrator rights -
ls: lists the files in a directory -
mv: moves or renames a file from the old name to the new name -
tail: shows the last lines of a file -
cat: prints the whole contents of a file -
grep: filters the text of a file according to the pattern -
less: lets you browse a file
Additionally, you can combine these commands using the | sign. For example:
sudo cat /var/log/syslog | grep error | tail
will first print the output of /var/log/syslog, then keep only the lines that say "error" and then the last 10 lines of that output.
We will also present a number of new commands such as service, logger. We will briefly explain what these commands do when they are shown. Remember that you can always read the manual page using man <command_name> to learn more about a command.
While you can copy and paste the commands that are presented in this lab, we recommend typing them out manually, to help with understanding and remembering them.
Listing system services
Let's look at the services that are installed in the machine. In order to do this, we will use the service command.
If you run service with parameters --status-all, it lists the state of services controlled by System V.
If you are interested in seeing only the services that are running, you can use the following command:
sudo service --status-all
Output:
[ - ] avahi-daemon
[ - ] cron
[ - ] cups
[ - ] cups-browsed
[ - ] dbus
[ - ] exim4
[ ? ] hwclock.sh
[ - ] procps
[ + ] rsyslog
[ - ] saned
[ + ] ssh
[ - ] sudo
[ + ] udev
Here you will see the following notations with respect to the services.
- +: Service is active/running
- -: Service is inactive/stopped
- ?: Can't determine whether service is active or not
Stopping and starting services
Alright, now that we've listed the services let's practice stopping and starting some of them. The first service that we are going to stop is the rsyslog service. This service is in charge of writing content to the log files, as in /var/log/syslog, /var/log/kern.log, /var/log/auth.log and others. Processes that generate output will send that output to the rsyslog service and the service will write it to the corresponding log files depending on how the system was configured.
Let's first start by checking the status of the service. We do this by using the service command with the status action:
sudo service rsyslog status
Output:
rsyslogd is running.
This is showing us a lot of information about the service: it's loaded (which means that the OS has the information about the service in memory), it's enabled (which means that it will start automatically on boot), it's active and running. It also tells us where to find some documentation about the service and more. Finally, it shows us the last log lines that this service generated.
We can see this service in action by using the logger command:
logger This is a test log entry
Top comments (0)