Chapter 1
Everything is a File
The Unix idea that everything is a file
Linux takes a strange but powerful shortcut: nearly anything you can interact with — a text file, a directory, a running process, a disk, a network socket, even your keyboard — shows up as a path under /. Once you can open, read, write, and close a file, you can talk to most of the OS the same way. Same four system calls, dozens of different things on the other side.
Regular file
Path on disk
/var/log/messagesSystem calls
open() → read() / write() → close()Plain bytes on disk. Most of what you edit, log, or build lives here.
$ stat /var/log/messages
File: /var/log/messages
Type: regular file
Mode: -rw-r--r--
Size: 12.4 KB
Uid: 1000 / asharib
Gid: 1000 / asharib
Same syscalls. Different backends. That's the whole trick.
Key takeaways
- open, read, write, and close work the same way on files, sockets, and devices
- /proc and /sys are virtual filesystems that expose kernel and process state as plain files
- /dev gives you hardware as files — you can read /dev/random or write to /dev/tty1
- Sockets, pipes, and FIFOs are file descriptors too — different backends, same API