How it works
The explanation, with examples you can run.
Where things live
| Path | What is there |
|---|---|
/etc | Configuration, mostly plain text |
/usr/bin, /usr/lib | Installed programs and libraries (/bin and /lib are symlinks to them on modern distributions) |
/var | Data that changes: /var/log, /var/lib (databases, package state), /var/cache |
/home, /root | Users' home directories |
/tmp, /run | Temporary files; /run holds runtime state such as PID files and sockets, emptied at boot |
/dev | Device files: /dev/null, /dev/sda, /dev/pts/0 |
/proc, /sys | The kernel's view of processes, devices and settings |
mount or findmnt lists what is mounted where; df -h shows how full each filesystem is.
/proc: ask the kernel about a process
sleep 300 &tr '\0' ' ' < /proc/$!/cmdline; echogrep -E '^(Name|State|PPid|VmRSS|Threads)' /proc/$!/statusreadlink /proc/$!/exe /proc/$!/cwdsleep 300 Name: sleepState: S (sleeping)PPid: 3631VmRSS: 1284 kBThreads: 1/usr/bin/sleep/Each PID has a directory with dozens of entries: cmdline (arguments, NUL-separated), environ, status, fd/ (open descriptors), maps (memory mappings), limits, cgroup, ns/ (namespaces) and more. This is where ps, top, lsof and free get their numbers. /proc/self is always the process doing the reading.
There are system-wide files too: /proc/meminfo, /proc/loadavg, /proc/cpuinfo, and /proc/sys/, where kernel settings live (sysctl vm.swappiness reads /proc/sys/vm/swappiness). None of it is stored anywhere:
stat -c '%s bytes' /proc/meminfo; wc -c < /proc/meminfo0 bytes1392/sys: devices and drivers
/sys (sysfs) exposes the kernel's device model as one value per file, which is easy for scripts to read:
ls /sys/class/netcat /sys/class/net/eth0/mtucat /sys/fs/cgroup/cgroup.controllersbonding_masterserspan0eth0gre0gretap0ip6_vti0ip6gre0ip6tnl0ip_vti0losit0tunl065535cpuset cpu io memory hugetlb pids rdmaBesides eth0 and loopback lo, Docker Desktop's kernel shows a set of tunnel devices that are never configured. /sys/class/net lists network interfaces, /sys/block disks, and /sys/fs/cgroup is the cgroup tree that resource limits and containers are built on. Some files are writable by root to change settings, and inside a container /sys is usually mounted read-only.
Device files
ls -l /dev/null shows crw-rw-rw- and 1, 3 where a size would be: c is a character device and 1, 3 are the major and minor numbers that select the driver. Reading /dev/urandom gives random bytes, writing to /dev/null discards data, and the terminal you type in is /dev/pts/N.
On macOS
macOS has a single tree from / as well, but no /proc or /sys. The same questions are answered by commands: ps, lsof -p <pid>, vm_stat, sysctl -a and ioreg. Its layout also differs: user homes are in /Users, and /tmp and /var are symlinks into /private.
Check yourself
3 questions. Get them all right to finish this topic.
0 of 3 right so far. Get all three to finish this topic.