The Linux Directory Structure, Explained
The Linux directory structure is fundamental to understanding how this powerful operating system widely used on servers and personal computers works.
In Linux, everything starts with the root directory, symbolized by a forward slash (/), which acts as the starting point from which all other directories branch.
Within this hierarchy, we will find essential directories such as /bin, which contains basic system executables, and /etc, where critical configuration files are stored.
The directory /home It is particularly important for users as it houses their personal files and settings.
Another key directory is /var, which saves variable files such as system logs and print queues.
Understanding how these directories are organized not only makes system navigation and management easier, but is also crucial for security and efficiency when administering Linux servers.
This hierarchical and logical structure not only optimizes system performance, but also allows for easy scalability and customization, features that make Linux a popular choice among developers and system administrators in Argentina and around the world.
If you're coming from Windows, the Linux filesystem structure may seem particularly strange.
The C:\ drive and drive letters are gone, replaced by / and cryptic-sounding directories, most of which have three-letter names.
The File System Hierarchy Standard (FHS) defines the structure of file systems in Linux and other similar operating systems UNIXHowever, Linux filesystems also contain some directories that are not yet defined by the standard.
/ – The root directory
Everything on your Linux system is located in the / directory, known as the root directory. You might think of the / directory as being similar to the C:\ directory on Windows, but this isn’t strictly true since Linux doesn’t have drive letters. While another partition would be located at D:\ on Windows, this other partition would appear in another folder under / on Linux.
/bin – Essential user binaries
The /bin directory contains essential user binaries (programs) that must be present when the system is mounted in single-user mode. Applications such as Firefox, if not installed as Snaps, are stored in /usr/bin, while important system programs and utilities, such as the bash shell, are located in /bin. The /usr directory may be stored on another partition. Placing these files in the /bin directory ensures that the system will have these important utilities even if no other filesystems are mounted. The /sbin directory is similar: it contains binaries essential to system administration.
/boot – Static boot files
The /boot directory contains the files needed to boot the system. For example, the GRUB bootloader files and your Linux kernels are stored here. However, the bootloader configuration files are not located here; they are in /etc with the other configuration files.
/cdrom – Historical mount point for CD-ROM
The /cdrom directory is not part of the FHS standard, but you will still find it on Ubuntu and other operating systems. It is a temporary location for CD-ROMs inserted into the system. However, the standard location for temporary media is within the /media directory.
/dev – Device files
Linux exposes devices as files, and the /dev directory contains a number of special files that represent devices. These are not actual files as we know them, but they appear as files. For example, /dev/sda represents the first SATA drive in the system. If you want to partition it, you can launch a partition editor and tell it to edit /dev/sda.
This directory also contains pseudodevices, which are virtual devices that do not actually correspond to hardware. For example, /dev/random produces random numbers. /dev/null is a special device that produces no output and automatically discards all input; when you pipe the output of a command to /dev/null, you discard it.
/etc – Configuration files
The /etc directory contains configuration files, which can usually be edited manually in a text editor. Note that the /etc/ directory contains system-wide configuration files. User-specific configuration files are located in each user's home directory.
/home – Home folders
The /home directory contains a home folder for each user. For example, if your username is bob, you have a home folder located at /home/bob. This home folder contains the user's data files and user-specific configuration files. Each user only has write access to their own home folder and must be granted elevated permissions (become root) to modify other files on the system.
/lib – Essential shared libraries
The /lib directory contains libraries needed by essential binaries in the /bin and /sbin folders. Libraries needed by binaries in the /usr/bin folder are located in /usr/lib. You will also see a counterpart /lib64 folder on 64-bit systems.
/lost+found – Recovered files
Every Linux filesystem has a lost+found directory. If the filesystem fails, a filesystem check will be performed at the next boot. Any corrupted files found will be placed in the lost+found directory, so you can try to recover as much data as possible.
The /media directory contains subdirectories where removable media devices inserted into your computer are mounted. For example, when you insert a CD into your Linux system, a directory will automatically be created inside the /media directory. You can access the contents of the CD inside this directory.
/mnt – Temporary mount points
Historically speaking, the /mnt directory is where system administrators would mount temporary filesystems while using them. For example, if you are mounting a Windows partition to perform some file recovery operations, you can mount it at /mnt/windows. However, you can mount other filesystems anywhere on the system.
/opt – Optional packages
The /opt directory contains subdirectories for optional software packages. It is commonly used by proprietary software that does not obey the standard file system hierarchy. For example, a proprietary program might dump its files into /opt/application when you install it.
/proc – Process and kernel files
The /proc directory is similar to the /dev directory in that it does not contain standard files. It contains special files that represent system and process information.
/root – Root home directory
The /root directory is the home directory of the root user. Instead of being located at /home/root, it is located at /root. This is distinct from /, which is the root directory of the system.
/run – Application state files
The /run directory provides applications with a standard place to store transient files they need, such as sockets and process IDs. These files cannot be stored in /tmp because they may be deleted.
/sbin – System administration binaries
The /sbin directory is similar to the /bin directory. It contains essential binary files that are generally intended to be run by the root user for system administration.
/snap – Storage for Snap packages
Another directory that isn't part of FHS but is common to see these days is /snap. It contains installed Snap packages and other files associated with Snap. Ubuntu now uses Snaps by default, but if you're using a different distribution that doesn't, you won't see this directory.
/srv – Service data
The /srv directory contains “data for services provided by the system.” If you were using the Apache HTTP Server to serve a website, you would probably store your website files in a directory within the /srv directory.
/tmp – Temporary files
Applications store temporary files in the /tmp directory. These files are usually deleted every time the system is rebooted and can be removed at any time using utilities such as systemd-tmpfiles.
/usr – User binaries and read-only data
The /usr directory contains applications and files used by users, as opposed to applications and files used by the system. For example, non-essential applications are located within the /usr/bin directory instead of the /bin directory, and non-essential system administration binaries are located in the /usr/sbin directory instead of the /sbin directory. Libraries for each are located within the /usr/lib directory. The /usr directory also contains other directories. For example, architecture-independent files such as graphics are located in /usr/share.
The /usr/local directory is where locally compiled applications are installed by default. This prevents them from messing up the rest of your system.
/var – Variable data files
The /var directory is the writable counterpart to the /usr directory, which should be read-only during normal operation. Log files and everything else that would normally be written to /usr during normal operation are written to the /var directory. For example, you'll find log files in /var/log.
For more detailed technical information about the Linux file system hierarchy, see the Filesystem hierarchy standard documentation.