How is the Linux filesystem organised?

It’s a tree, and like all trees, it starts with the root.

If you want all the specifics, I suggest familiarising yourself with the Filesystem Hierarchy Standard (FHS). There’s a lot of detail there; the most important thing for you to understand is that, when coming from a Windows to a Linux environment, you don’t have “drive names”. There’s no “C:” or whatever. Everything starts at “/”. (That’s the root of the filesystem.)

To see what’s available from the root, drop into a command line (terminal) and type the commands:

cd /
ls

The results will look something like this (this is my default Ubuntu 21.04 install):

Everything in dark blue is a directory. Everything in white is a text file. Everything in green (nothing in the shot above) is exceutable. The directories you’ll find yourself fiddling with the most include /etc, /home, /media, and /var.

/etc

/etc (pronounced et-see) has all the configuration files. Again default configuration of Ubuntu 21.04, here’s what I’ve got:

Obviously there’s a lot in there. Again, anything in white is a text file; anything in dark blue is a directory. Notice the commands I’ve used: ls and cd.

“ls” gives you a directory “listing”.

“cd” changes to a directory.

“more”, “less”, and “cat” will show you the contents of text files; it’s useful to read up on how these commands work. My tendency is to use “less”, as it presents an easily-navigable, paged display of a file’s contents.

Note: when in doubt, RTFM. (You don’t want anyone to tell you “RTFM” when you ask a dumb question (there are dumb questions)). Read. The. Fucking. Manual. This means to read the manual page for whatever command is in question. For example, if you want to know how “less” works, don’t ask someone “hey, how does ‘less’ work?” They will be within their rights to tell you to RTFM.) To read the (fucking) manual, type this at a command prompt:

man less

As an example, you’ll see something like this:

Follow the on-screen instructions to learn how to navigate a paged viewer like this. (That is, RTFM; I’m not going to re-invent the manual here because FTN.)

It is well worth your time to get to know how these common, basic commands work; they’re extremely powerful and will help you navigate and administer your computer like a fucking boss.

Anyway. Have a cruise around /etc and see what’s in there. Don’t worry: unless you’re the administrator, you can’t break anything.

/home

Linux, like all UNIX-oriented operating systems, is a multi-user system. If you installed fresh and created one user, there will be only one sub-directory in /home. It will be named after you. Mine is /home/brian/.

There are lots of other users on the system. You can view them in the file /etc/passwd:

You’ll never interact with most of them. It’s mostly just you and root, assuming you are your own administrator.

You might be thinking: what’s the freaking point to all this complication? Well, if, in principle, the administrator and users are separated, it’s much more difficult for malware to affect the system. Notice some of the user names in that file: www-data, mail, lp, and so on. They all have different jobs, and those jobs are logically separated from both users and the administrator. In a well-maintained system, even if www-data is compromised, that user cannot affect things like the printer, or you! If you’re compromised, you can’t affect the printer, or the web server, or whatever.

Notice, there are no subdirectories in /home for any of these utility users. That’s what we expect; they never log in; they never use the system, as you do. Sub-directories in /home are legitimate users set up by the administrator.

/media

If you plug in a USB drive, or pop a camera card in a slot, or whatever, that “device” will be “mounted” in a subdirectory of /media.

/media is reserved for removeable devices.

This is important: a device is anything attached to the computer. This includes the keyboard, the wifi controller, the screen, a printer, the hard drive, anything. All of those things are represented somewhere in the filesystem — as a “file”. This simplifies everything. If a printer can be treated like a file, then I can control access to the printer the same way I control access to a file. Easy peasy.

Briefly: the very concept of a file, in the UNIX world, includes the very concept of permission (more on this in a separate article). This is very important: the very idea of security is built in to the very concept of what it’s like to exist in a UNIX-style environment. (For ages, the idea of security was separate from the idea of a file, in a Microsoft environment. This made everything quite vulnerable, and this structural concern is among the reasons why there were so many ways to infect a Microsoft environment with malware. But I digress — and I guess Microsoft has changed its ways by now, I hear. I dunno. I don’t pay attention to those billionaire fuckers.)

So anyway, when you plug in a new device, the system recognises the presence of the new device and “mounts” it. This means that it gets its own spot in the filesystem. (Ages ago, this was all a manual process; nowadays, it’s all very simple, so lucky you!) When the system mounts something new, it will be mounted to a subdirectory of /media corresponding to the user’s name. In my case, anything I mount will live in /media/brian/.

/var

This is a directory where “variable” things go — things that we expect will change as the operating system operates. A specially useful example are the files in /var/log/. These are the log files, where the system tracks the things that happen — depending on how you’ve configured it to keep track of such things. When errors occur, they’ll be in here somewhere. When services restart, you’ll find logs of that as well. Have a bounce around in here and view some of the files. It’s good fun.

Summary

You’ve entered a different world. There’s a lot to learn at first, but everything is very deliberately designed — especially for security — and has been operating successfully for fifty years. It’s worth spending a little time getting to know how the filesystem works, and how it contributes to both the security and stability of a UNIX-oriented system like Linux. This is best done through the command line, and the manual.

When in doubt, indeed, RTFM.