💾 Archived View for yujiri.xyz › software › guide › filesystem.gmi captured on 2023-07-10 at 13:54:52. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2023-06-14)

➡️ Next capture (2023-09-08)

🚧 View Differences

-=-=-=-=-=-=-

yujiri.xyz

Software

Learn programming for good instead of profit

Filesystem concepts

Here I'm gonna talk about concepts like files, folders, paths, partitions, and mount points.

Files and folders

This is pretty basic information, but I don't want to leave any gaps, so I'll explain it even though you probably already know.

A file is an object stored on your storage device. Fundamentally, it's a series of bytes with a name and some other properties.

A folder is a container of files, much like a physical folder. It's usually called a directory on Unix-like operating systems, but I call them folders just because it's shorter.

Historical note on Unix, POSIX, and Linux

All the files on your computer are organized hierarchically, like a tree, with folders that contain other folders. For example, on most operating systems you have a "home folder" which contains other folders like Documents, Downloads, and Desktop, which themselves contain various files.

The "root" folder, written `/` (or `C:\` on Windows), is the one that ultimately contains everything else.

Paths

A file *path* is a series of folders that specifies how to get to a specific file. Folders are separated with slahes. For example, on Linux the path to one your files might be `/home/bob/Downloads/meme.png`. This means you have a folder just inside root called `home` (which contains separate home folders for any number of users), a folder inside that called `bob` which is the home for a specific user, a folder inside `bob` called `Downloads` and a file inside `Downloads` called `meme.png`.

Paths that start from the root are called absolute paths. There's also relative paths, which are interpreted as starting from wherever you currently are. For example, if you're in `/home/bob`, the relative path `Downloads/meme.png` means `/home/bob/Downloads/meme.png`. But if you're in `/home/alice`, it would mean `/home/alice/Downloads/meme.png`.

The special path `.` means the current folder. If you're in `/home/bob`, `.` means `/home/bob`, and `./meme.png` means `/home/bob/meme.png`.

The special path `..` means the parent of the current folder. If you're in `/home/bob`, `..` means `/home`, and `../alice` means `/home/alice`.

Extra slashes in a path typically don't mean anything. For example, Linux interprets `/home//bob` the same as `/home/bob` (but some programs might get confused by it). A trailing slash, like `/home/bob/`, is also typically optional, but it does mean that the path is a folder. If you try to open `meme.png/`, you probably get an error saying "Not a directory".

Filesystem

A filesystem is a way of arranging files on a storage device. If you wonder what challenges a filesystem faces, consider things like:

A filesystem is an answer to these questions. As the questions suggest, filesystems are very complex and difficult to design well. Most operating systems support multiple filesystems, but have one that they use by default for your main storage device. On most Linux distributions, the default filesystem is either ext4 or btrfs.

The word 'filesystem' can also refer to an instance of a filesystem. For example, all the files on your storage device are said to be in your filesystem (might be more than one, see the next section).

Partitions

Storage devices are usually divided into a few sections, called partitions, that each have their own filesystem. As an example, if you go through a Linux distribution's guided installer with the default settings, it'll probably create:

If you're a tinkerer, or depending on the distribution's installer, you might have a different layout. For example, your primary partition might be divided into a partition for installed packages and a partition for user data. I won't go into the pros and cons of these choices.

Mount

To mount a filesystem means to tell the kernel to make it available at some path underneath `/`. The one mounted directly at `/` is your main filesystem. Your boot partition's filesytem might be mounted at `/boot` (so things under `/boot` are files from the boot partition, not your main one). If you have a separate partition for user data, its filesystem is mounted at `/home`. If you have a flash drive connected, it might be mounted at `/mnt` or `/media`.

The `mount` command is used to manage filesystem mounts. If you run it with no parameters it'll show all the mounted filesystems. If it shows you a big list, probably most of them are virtual filesystems that don't represent actual files on storage. For example, the one mounted at `/dev` contains virtual files that represent hardware devices like your storage, mouse and keyboard. The one mounted at `/proc` contains virtual files that represent running processes.

contact

subscribe via RSS