On to the next interesting top-level directory within the Linux filesystem: the /etc/ directory. Pronounced et-c as in et-cetera, it is used to store configuration files for both system software as well as user software. Let's see what it contains:
reader@ubuntu:/etc# ls
acpi console-setup ethertypes inputrc logrotate.conf network python3 shadow ucf.conf
...<SNIPPED>:
We snipped the preceding output to only the top line of our system. If you followed along with the example (and you should!) you will see well over 150 files and directories. We will print a particularly interesting one using the cat command:
reader@ubuntu:/etc$ cat fstab
UUID=376cd784-7c8f-11e8-a415-080027a7d0ea / ext4 defaults 0 0
/swap.img none swap sw 0 0
reader@ubuntu:/etc$
What we're seeing here is the file systems table, or fstab file. It contains the instructions for Linux to mount the filesystems at each start. As we can see here, we're referencing a partition by its Universally Unique Identifier (UUID) and we're mounting it on /, so as the root filesystem. It's of type ext4, mounted using options defaults. The last two zeros deal with backups and checks at the start of the system. On the second line, we see we're using a file as swap space. Swap is used in case there isn't enough memory available to the system, which can be compensated for by writing it to disk (but incurring a hefty performance penalty, since a disk is much slower than RAM).
Another interesting configuration file in the /etc/ directory is the passwd file. While it sounds like password, don't worry, those aren't stored there. Let's check the contents using the less command:
reader@ubuntu:/etc$ less passwd
This will open the file in a so-called pager, in read-only mode. less uses Vim commands, so you can quit by pressing the Q on your keyboard. If the file is larger than your screen, you can navigate up and down with the Vim keystrokes: either the arrow keys or by using J and K. When in the less, the screen should look something like the following:
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
...<SNIPPED>:
sshd:x:110:65534::/run/sshd:/usr/sbin/nologin
reader:x:1000:1004:Learn Linux Shell Scripting:/home/reader:/bin/bash
This file contains information about all users on the system. In order, the fields separated by the : denote the following:
| Username | Password | User ID (UID) | Group ID (GID) | User real name | Home directory |
Users' default shell |
While there is a password field here, this is because of legacy reasons; the (hashed!) password has been moved to the /etc/shadow file, which can only be read by the root superuser. We will cover the UID and GID in the next chapter; the other fields should be clear by now.
These are just two examples of configuration files found in the /etc/ directory (important ones though!).