Understanding the filesystem is important if you want to know how data is stored and retrieved, but really, the term might be somewhat confusing in Linux, as it means two different things.
A filesystem can be the default directory structure (which is the structure and logic rules used to manage the groups of data and their names), and it can be the actual filesystem we choose when formatting a volume (ext4, XFS, JFS, and the likes), which is outside the scope of this guide.
Have you ever noticed a slash (/) when entering a directory? The slash is considered the beginning of the file system, and sub-directories branch out from there. This is like going into a big building with many rooms, you start from a door, which leads you into the other rooms (think subdirectory).
Let's take the /home directory, for example, this directory exists at the root level of the filesystem, which is why we have the slash depicting the beginning.
Let's assume your home directory is /home/your-username, this means the directory your-username is inside the directory home, and thus the home directory is the beginning of the filesystem.
Use the ls command against the forward-slash to see how the filesystem is structured:
ls -la /
This would show you the listing of the root directory, which is the directory that is at the top of the directory hierarchy and that contains all other directories and files on the system. You'll see the home directory, var, usr, and others.
The directory structure you see is the default directory and is part of the Filesystem Hierarchy Standard (FHS), which is a set of guidelines that defines how the directory structure is laid out. This specification defines the names of the directories, where they are located, and what they are used for. This is why you see a similar structure across Linux distros.
If you are adding a volume to your server, you format that volume and then mount (attach) the volume to a directory on the filesystem, this can be included anywhere in the filesystem e.g the /mnt or your chosen path.
Here is a pdf that explains the structure in-depth and what they are used for Filesystem Hierarchy Standard (FHS) PDF
The below table outline the most used directories and their purpose.
Directory | Used for |
/ | The beginning of the filesystem, sub-directories branch out from there. |
/home | The user home directories, each time a new user is created, a directory in the name of the user is created within the home directory which contains other personal user directories. |
/root | The home directory for root, it doesn't have a directory underneath /home and should never be confused with ‘/ |
/media | Temporary mount directory is created for removable devices e.g, media/cdrom, flash drives |
/mnt | For volumes that are intended to stay mounted for a while |
/opt | Additional software packages e.g third party application |
/bin | Essential user binaries (ls, cp, and so on) |
/proc | Virtual filesystem for OS-level components |
/usr/bin | A majority of user commands |
/etc | Application’s configuration files, startup, shutdown, start, stop script for every individual program. |
/var | The contents of this file is expected to grow. This directory contains log, lock, spool, mail, and temp files. |
/tmp | System’s Temporary Directory, Accessible by users and root. Stores temporary files for user and system, till next boot. |
/boot | Holds important files during the boot-up process, including Linux Kernel. |
There are more, but these are the main ones, the take away is that the filesystem is the structure and logic rules used to manage the groups of data and their names