Learn › Linux Foundations › Important Files and Paths
Final test: Chapter 4, Important Files and Paths. Twenty-five objectives on a real Debian 12 server: the top level of /, the files in /etc (passwd, group, hosts, hostname, os-release, fstab, the site settings), the live files under /proc, and /sys/class/net, by absolute path and by standing in the directory. Fifty minutes, graded from the commands you run and where you stand.
This chapter covers the following topics:
What you already know: Chapter 2 taught ls, cd, absolute and relative paths and tree inside your home directory, and Chapter 3 taught the manual. This chapter leaves the home directory and reads the files the system keeps about itself.
Objectives
After this chapter you can:
Before you start a machine, each exercise shows a rehearsal terminal. It checks the requested command against an example and does not change Linux files. Start one real practice machine and use its admin@server1 shell for the exercises. Commands run there, so a wrong command can still have an effect even when the lesson does not mark the exercise complete.
During one connection, your shell keeps its current directory. A new connection may start a fresh shell on the same machine; use pwd to check where you are. This chapter walks from your home directory to /, then to /etc and /proc; the two exercises with a bare file name say where to stand.
The final Test Room starts a separate Debian 12 server with this chapter's files and checks its objectives automatically as you work.
Five questions before the material. A wrong answer costs nothing: the explanation states the fact and names the section that teaches it.
>>> Every file sits in one tree, and / is its top, the root directory. Every absolute path starts there. Section 4.1.
>>> /etc holds system and program configuration, often as text files. Their permissions differ: this chapter reads public examples, while /etc/shadow is restricted. /usr holds many installed programs. Section 4.2.
>>> Despite its name, /etc/passwd holds no passwords; their protected records are in /etc/shadow, which this ordinary account cannot read. It lists local account records for people and services, one line of seven fields each. Section 4.4.
>>> Nothing under /proc is on disk. The kernel answers each read with the current values, so a file there is a live report, not a stored document. Section 4.10.
>>> /etc/hosts contains the local address entered for db1 on this server. You can read that mapping without testing a connection. Section 4.6.
Every file on a Linux system sits in one tree of directories. The tree has one top, the root directory, written /. Chapter 2 wrote absolute paths from it: /home/admin is the directory admin inside the directory home inside /. There is no second tree and no drive letter; a second disk is attached somewhere inside this one tree, and Section 4.9 shows the file that records where.
ls / lists the top level from wherever you stand:
prompt: admin@server1:~$ answer: ls / output: bin etc initrd.img.old lost+found opt run sys var boot home lib media proc sbin tmp vmlinuz dev initrd.img lib64 mnt root srv usr vmlinuz.old hint: Section 4.1. The listing command, then the path /: one character, the shortest absolute path there is.
Twenty-four names, sorted and printed in columns. A Debian system carries most of this set at its top level, and other Linux systems are close to it. Section 4.2 says what the important ones hold. A plain listing does not say which names are directories and which are files or links; tree does.
tree from Section 2.7, with -L 1 so it stops at one level, draws the same names with their types:
prompt: admin@server1:~$ answer: tree -L 1 / ||| tree / -L 1 output: / ├── bin -> usr/bin ├── boot ├── dev ├── etc ├── home ├── initrd.img -> boot/initrd.img-6.1.0-47-amd64 ├── initrd.img.old -> boot/initrd.img-6.1.0-47-amd64 ├── lib -> usr/lib ├── lib64 -> usr/lib64 ├── lost+found ├── media ├── mnt ├── opt ├── proc ├── root ├── run ├── sbin -> usr/sbin ├── srv ├── sys ├── tmp ├── usr ├── var ├── vmlinuz -> boot/vmlinuz-6.1.0-47-amd64 └── vmlinuz.old -> boot/vmlinuz-6.1.0-47-amd64
21 directories, 4 files hint: Section 4.1. The drawing command from Chapter 2, with its depth option -L set to 1, then the path /.
Eight of the twenty-four names carry an arrow, so eight of them are symbolic links: a symbolic link is a name that points at another path (Section 2.4). bin -> usr/bin, sbin -> usr/sbin, lib -> usr/lib and lib64 -> usr/lib64 point into /usr. These links keep older paths working while many system programs and libraries live under /usr. Software can also be installed in other directories. vmlinuz and initrd.img point at the two files the machine boots from, inside /boot. vmlinuz is the kernel, the program at the core of the system, and the number in its target is the kernel version.
The two .old names point at the same two files here, because this server has one kernel installed; on a machine that has been through a kernel upgrade they point at the previous one. The last line, 21 directories, 4 files, counts the four links to files as files. It also counts / itself as one of the directories: 20 directories inside / plus 4 files is the 24 names above.
/ is a directory like any other, so you can stand in it. Move there with its path, the shortest absolute path there is:
prompt: admin@server1:~$ answer: cd / output: hint: Section 4.1. The change-directory command, then the one-character path /.
You are standing in / now, where Exercise 4-3 put you. Confirm it with the Chapter 2 command that prints the working directory:
prompt: admin@server1:/$ answer: pwd output: / hint: Section 4.1. Three letters, no options: the Chapter 2 command that prints the working directory.
The working directory is /, and the prompt shows it: admin@server1:/$. Chapter 2 wrote your home as ~; the root has no shortcut, because its own name is already one character.
ls with no path lists the working directory (Section 2.2), which is now the root:
prompt: admin@server1:/$ answer: ls output: bin etc initrd.img.old lost+found opt run sys var boot home lib media proc sbin tmp vmlinuz dev initrd.img lib64 mnt root srv usr vmlinuz.old hint: Section 4.1. The listing command with no path at all, so it lists where you stand.
The same twenty-four names as ls /. From here every top-level directory is one name away, and the rest of this chapter reads them by their absolute paths, which work from here or from anywhere else.
The top-level directories on this Debian server follow common Linux conventions, so a file you have never seen can often be found by asking what kind of file it is. Other systems may install a different set of directories. The directories this track uses:
| Directory | What it holds |
|---|---|
/etc | Configuration: the settings of the system and of installed programs, as plain text files. Sections 4.3 to 4.9 read seven of them. |
/home | The home directories of ordinary accounts. Yours is /home/admin. |
/root | The home directory of root, the administrator account. Not under /home. |
/usr | Installed programs, their libraries and their documentation. /usr/bin holds the programs you type: ls, cat, tree. |
/bin, /sbin, /lib | Links into /usr, kept so old paths still work. |
/var | Files that grow and change while the system runs: logs in /var/log, caches, mail, print and job queues. |
/tmp | Temporary files. Anything here may be deleted at reboot. |
/boot | The kernel and the files needed to start it. |
/dev | Special files for some devices, including disks and terminals. |
/proc | Live reports from the kernel about processes and the system; not stored on disk. Section 4.10. |
/sys | Live reports from the kernel about hardware; not stored on disk. Section 4.14. |
/mnt, /media | Places to attach other disks, by hand or automatically. |
/opt, /srv | Software installed as one self-contained unit; data served to the network. |
The same directories as a picture. Click any one:
{ "caption": "The directories this track uses. The two tinted ones are live: the kernel produces their contents as you read.", "highlight": [ "/proc", "/sys" ], "annotations": { "/etc": { "tag": "configuration", "note": "Configuration: the settings of the system and of installed programs, as plain text files." }, "/home": { "tag": "home directories", "note": "The home directories of ordinary accounts. Yours is /home/admin; operator has /home/operator." }, "/root": { "tag": "root's home", "note": "The home directory of root, the administrator account. Not under /home, and not readable by you." }, "/usr": { "tag": "installed software", "note": "Installed programs, libraries and documentation. /usr/bin holds the programs you type." }, "/var": { "tag": "variable data", "note": "Files that grow while the system runs: logs in /var/log, caches, mail, queues." }, "/tmp": { "tag": "temporary", "note": "Temporary files. Anything here may be deleted at reboot." }, "/boot": { "tag": "kernel", "note": "The kernel (vmlinuz) and the files needed to start it." }, "/dev": { "tag": "devices", "note": "Special files for some devices, including disks and terminals." }, "/proc": { "tag": "live", "note": "Live reports from the kernel about processes and the system. Not on disk; produced when read." }, "/sys": { "tag": "live", "note": "Live reports from the kernel about hardware, one directory per device. Not on disk." } }, "tree": { "name": "/", "children": [ { "name": "etc", "children": [] }, { "name": "home", "children": [] }, { "name": "root", "children": [] }, { "name": "usr", "children": [] }, { "name": "var", "children": [] }, { "name": "tmp", "children": [] }, { "name": "boot", "children": [] }, { "name": "dev", "children": [] }, { "name": "proc", "children": [] }, { "name": "sys", "children": [] } ] } }
History. The layout has a written standard, the Filesystem Hierarchy Standard. Its first version was published in 1994 under the name FSSTND, it took the name FHS in 1997, and version 3.0 followed in 2015. /proc is older than the standard: it appeared in Eighth Edition Unix in 1984, and Linux has had its own since 1992.
You are standing in /. Start with the directory this chapter spends most of its time in, /etc, which holds the configuration of the whole system:
prompt: admin@server1:/$ answer: ls /etc ||| ls /etc/ output: NetworkManager groff mke2fs.conf security X11 group modprobe.d selinux adduser.conf group- modules sensors.d adjtime grub.d modules-load.d sensors3.conf alternatives gshadow motd server1 apparmor gshadow- mtab services apparmor.d gss nanorc shadow apt hdparm.conf netconfig shadow- bash.bashrc host.conf network shells bash_completion hostname networks skel bindresvport.blacklist hosts nftables.conf ssh binfmt.d hosts.allow nsswitch.conf ssl ca-certificates hosts.deny opt subgid ca-certificates.conf init.d os-release subgid- chrony initramfs-tools pam.conf subuid cloud inputrc pam.d subuid- console-setup iproute2 passwd sudo.conf cron.d issue passwd- sudo_logsrvd.conf cron.daily issue.net perl sudoers cron.hourly kernel ppp sudoers.d cron.monthly kernel-img.conf profile sv cron.weekly lab profile.d sysctl.conf cron.yearly ld.so.cache protocols sysctl.d crontab ld.so.conf python3 sysstat dbus-1 ld.so.conf.d python3.11 systemd debconf.conf ldap rc0.d terminfo debian_version libaudit.conf rc1.d timezone default locale.alias rc2.d tmpfiles.d deluser.conf locale.gen rc3.d ucf.conf dhcp localtime rc4.d udev dictionaries-common login.defs rc5.d ufw dpkg logrotate.conf rc6.d update-motd.d e2scrub.conf logrotate.d rcS.d vim emacs machine-id reportbug.conf wgetrc environment magic resolv.conf xattr.conf ethertypes magic.mime rmt xdg fstab manpath.config rpc gai.conf mime.types runit hint: Section 4.2. The listing command, then the absolute path /etc.
The list is long, and it is read by name: you arrive at /etc knowing which file you want. Six of these names belong to this chapter: passwd, group, hosts, hostname, os-release and fstab. One directory here belongs to the organization that runs this server, server1, which Section 4.3 opens; lab belongs to the grading system. Many names end in .d: each is a directory of small files that together form one configuration, cron.d for scheduled jobs, sudoers.d for the rules Chapter 7 reads.
You are still standing in /. /home holds one directory per ordinary account, each of them that account's home directory. List /home:
prompt: admin@server1:/$ answer: ls /home ||| ls /home/ output: admin deploy operator hint: Section 4.2. The listing command, then the absolute path /home.
Three home directories. admin is yours and operator is the other ordinary account: Section 4.4 reads its account line, and Chapter 7 switches to it. deploy is a service account whose home is also under /home. root is not here; its home is /root.
You are still standing in /. /var holds the files that grow while the system runs: logs, mail, spooled jobs and caches. List /var:
prompt: admin@server1:/$ answer: ls /var ||| ls /var/ output: backups cache lib local lock log mail opt run spool tmp hint: Section 4.2. The listing command, then the absolute path /var.
The name that matters most is log: /var/log is where the system and its services write what happened, one line at a time. Chapter 7 reads /var/log/auth.log, the record of logins and of sudo. backups, cache, mail, spool and tmp are the other places where files grow on their own.
You are still standing in /. /usr holds the software the distribution installed: the programs you type, the libraries they share, and their documentation. List /usr:
prompt: admin@server1:/$ answer: ls /usr ||| ls /usr/ output: bin games include lib lib64 libexec local sbin share src hint: Section 4.2. The listing command, then the absolute path /usr.
bin holds the programs you type, lib the libraries they share, share their documentation and data, including the manual pages Chapter 3 read. When you type ls, the shell runs /usr/bin/ls. The bin -> usr/bin link from Section 4.1 points here.
The files in /etc are plain text, so one tool reads them all. cat prints a file to the terminal, from its first line to its last, and returns to the prompt. Chapter 5 covers cat fully, with its options and the pagers that show long files one screen at a time; this chapter uses only the bare form: cat, a space, the path. You are standing in / for the next four exercises, but every path in them starts with /, so each one reads the same file from any directory on the machine.
The organization keeps its own settings for this server in a directory of its own under /etc. The target is /etc/server1/site.conf:
Worked command: cat /etc/hostname. cat reads the named file and sends its contents to the terminal. It does not open an editor or modify the file. The leading / makes the path absolute, so this example does not depend on your current directory.
prompt: admin@server1:/$ answer: cat /etc/server1/site.conf output:
SITE_NAME="Northwind Bakery" WEB_ROOT=/home/admin/website/current LOG_DIR=/home/admin/logs BACKUP_HOST=backup1 DB_HOST=db1 hint: Section 4.3. The reading tool, then the absolute path /etc/server1/site.conf.
Six lines. The first starts with # and is a comment: a line written for people and ignored by programs. The rest are KEY=VALUE pairs, one setting per line, the shape most configuration files in /etc use. Two of the values are the names of other machines, backup1 and db1; Section 4.6 shows where those names are turned into addresses.
Local accounts on this server have one record each in /etc/passwd. An account is a name the system knows, with a number behind it, whether a person logs in with it or a service runs under it. Other Linux machines may also look up accounts from a directory service, so this file need not list everyone they recognize. On this server the file is readable
Practice Chapter 4. Important Files and Paths: /etc, /proc and /sys in a real Linux terminal at The Linux Camp. Progress is verified automatically as you type commands on the machine.