In page 227 of the wonderful book “The Dream Machine” by M. Mitchell Waldrop, covered in a previous issue, telling the story of the early development of computers, we can learn that Fernando Corbató and his team were busy in 1965 adding a new feature to CTSS, the first interactive and multi-user operating system for the IBM 7094 computer. That feature was, you guessed it, a file system.
CTSS’s fundamental model of human-computer interaction (…) can still be found today at the heart of MS-DOS, Windows, Macintosh, Linux, and many other operating systems. So can such innovations as CTSS’s “hierarchical” file system, a scheme devised by Corbató and his team to enable individual groups and individual users to organize their personal files into “directories” and “subdirectories” on the 7094’s hard disks. (In modern-day Windows and Macintosh systems, of course, such directories are called folders.)
Waldrop forgot to mention Linux, itself a derivative of Unix, where a quick man 7 hier command will display the complete description of the filesystem hierarchy, finally providing some light on the intricacies of the various /etc, /usr, /home, and /var folders.
Beyond the mere organization of data, the Unix lineage of operating systems took Corbató’s hierarchical concept and elevated it into something akin to an arcane voodoo artiluge. This is true of Linux, macOS, and the BSDs, but not so much Android and iOS, because let us be honest, it is quite tough to use a command line with these last two, and iOS’s “File” application is an absolute clusterfuck of an idea.
This “feature” of a voodoo-like file system is probably one of the most salient aspects of Unix-based systems, and it is captured in a famous, four-word axiom of the Unix philosophy: everything is a file. This is one of those phrases that have echoed throughout the ages, similar to you are doing it wrong or the network is the computer; or at least, it did until file systems disappeared beneath the rugged interface of an S3 bucket somewhere in 2005.
To understand the reason behind this idea, we have to look back to the creators of Unix at Bell Labs: Ken Thompson, Dennis Ritchie, and Douglas McIlroy. When they were building Unix from the ashes of the overly complex Multics project, they sought simplicity. Instead of creating a dozen different APIs to talk to a hard drive, a keyboard, a printer, and a network connection, they created just one.
Scarcity is the actual mother of invention, because nobody needed this, really.
They decided that if an abstraction worked for a text document, it should work for everything. (I know, stay with me.) In their worldview, a file was simply a stream of bytes. Consequently, the same system calls used to manipulate a text file (open(), read(), write(), and close()) could be used to interact with virtually every component of the computer. Because why not.
(See? The world was much simpler back in the day.)
Take a walk through the /dev (device) directory on any modern Linux or macOS machine, and you are no longer looking at data stored on a magnetic platter or solid-state drive; you are looking at the hardware itself, masquerading as files!
It goes even deeper. When you type on your keyboard or watch text scroll on your screen, you are interacting with a TTY device (like /dev/tty), a direct descendant of the physical Teletype machines of the 1970s. If you wanted to send text directly to a parallel-port printer in the early days of Linux, you did not need a dedicated printing application; you simply redirected your text into the printer’s file: echo "Hello World" > /dev/lp0. Of course, you would still need a printer, which can be a problem in and of itself.
There are “block devices” like /dev/sda or /dev/nvme0n1, which represent your actual physical hard drives. You can read them directly, bypassing the traditional file system entirely, simply by pointing a tool like cat or dd at them.
Then there are the esoteric, conceptual devices. Need an endless stream of zeroes to wipe a hard drive? Read from /dev/zero. Need a place to send error messages so you never have to see them again? Throw them into the abyss of /dev/null, the file system’s built-in black hole. Need cryptographic randomness? Just read from /dev/urandom, where the kernel distills the chaotic entropy of hardware interrupts into a stream of random bytes. Try it by yourself: run cat /dev/urandom | hexdump -C | head -n 5 in your nearest terminal (well, do not try it if you are running Windows) and you will see some… well, random garbage printed out.
The “everything is a file” philosophy enters the realm of LSD when we look at Inter-Process Communication, or “IPC”. How do two completely isolated programs talk to each other in Unix? By reading and writing to files, of course!
The most iconic manifestation of this is the pipe (represented by the | character in your shell). Conceived by Douglas McIlroy, the pipe takes the standard output (file descriptor 1) of one program and connects it to the standard input (file descriptor 0) of another. But Unix also allows for named pipes: again, you guessed it: persistent files residing on the disk that act as FIFO (First In, First Out) queues. One program opens the file and writes to it, another opens the file and reads from it. To the programs involved, they are just doing standard file I/O.
This abstraction scales up to networking. When you browse the web, your browser communicates over a network socket. In Unix, that socket is treated as a file descriptor. The program writes its HTTP request to the “file” and reads the web server’s response from that same “file.” The underlying networking stack (TCP handshakes, IP routing, Ethernet frames) is completely hidden behind the familiar read() and write() interface. Even complex virtualization tools like Docker rely on this, listening for instructions via a Unix domain socket, usually located at /var/run/docker.sock. Anyone reading this who has ever debugged REST APIs using curl knows this mechanism very well.
If Unix established the “everything is a file” paradigm, the research operating system Plan 9 from Bell Labs perfected it, and modern Linux heavily borrowed from there, taking it from LSD to full-on Ayahuasca level.
Boot up a Linux machine and navigate to /proc. The files you see there take up exactly zero bytes on your hard drive. They exist entirely in the computer’s RAM, dynamically generated by the kernel on the fly. Magic!
The /proc (process) filesystem is an illusion that maps the internal state of the operating system into the file hierarchy. Want to know what CPU you are running? You do not need a specialized hardware diagnostic tool; you just type cat /proc/cpuinfo. Want to see how much memory is free? cat /proc/meminfo.
Every running program on your computer has a dedicated directory in /proc named after its Process ID (PID). Inside that directory are files containing everything from the exact command used to launch the program, to the environmental variables it holds, to the specific areas of memory it is currently using.
Similarly, the /sys (sysfs) directory provides a window into the Linux kernel’s device model. If you are on a Linux laptop and want to check your battery percentage, you do not need a graphical widget. Oh noes, that is for simpleton users. No, you, my dear IT expert, you can simply cat /sys/class/power_supply/BAT0/capacity. Want to change the brightness of your screen? Just write a new number into /sys/class/backlight/intel_backlight/brightness. Und so weiter.
Good luck remembering all of those commands, but hey! Now you know you can.
The Unix file abstraction is considered by many one of the greatest engineering triumphs in software history. Sadly, those “many” are not simple computer users, but actual experts of the industry. Of course, if you look at it closely, yes, it enables composability. Keyboards, displays, network connections, random number generators, and kernel diagnostics all share the exact same interface as a simple text file, making this standard toolkit universally applicable.
I personally think that the Unix file system analogy is not enough. We should be able to listen to Mark Snow’s famous “X-Files Theme” by just typing cat /music/spotify/track/3pDZSfOSszYWMYygDiuPJx. We should be able to swipe Tinder profiles using left /social/tinder/34564576891457. We should be able to search and buy plane tickets with fly /AF/CDG/PPT/business/2027-03-02/2027-04-10. You get the idea. And to be honest, none of the scenarios above would be too complicated to implement (well, except the airline thing, really).
But the truth is that in terms of usability, let us be honest, it is a terrible system. Even for people from the world of IT, it is usually impossible to actually remember all of the myriad combinations available, and which one represents what. You might have a few in mind, or you might create an alias to quickly type one or the other, but the fact that “everything is a file” is barely more than a curiosity to pretty much everyone. Add some complexity points if you switch from Linux to FreeBSD, and suddenly you must cat for files in other locations.
As I said at the beginning, we have not cared about file systems for more than 20 years now. (Remember when you could not have spaces in DOS filenames until circa 1995? If you can, I have bad news for you: you are old.) In Linux, arguably the most nerdy of all operating systems, you might still be choosing between ZFS, EXT, BTRFS, or XFS when formatting a new drive, but nobody cares anymore, really. Windows users are fine with NTFS, Mac users do not even know what APFS is. Gone are the days of using fdisk. Nostalgic OS/2 users might even remember HPFS and shed a tear. Most users probably even use some kind of encryption on top of their file system, just in case. And some ultra-nerd Linux users might be even be interested in Gobolinux, a distribution that literally reorganized the whole hierarchy for… reasons.
These days people are more interested in knowing whether we have a fast SSD in our home computer, or if we have properly configured Ceph, Gluster, or Longhorn within our Kubernetes cluster. And if all else fails, you can always format your USB thumbdrives with FAT32 and make sure that virtually every operating system on Earth can read and write to it.
But whatever you do, remember that this article only caters to systems deriving from Unix, and in particular, do not even think of creating a file named CON on your Windows hard disk. You have been warned.
Cover photo by Alexey Demidov on Unsplash.