Linux Directory Structure Explained

The linux directory structure explained. What are the key directories involved and what are they for?

Linux Directory Structure Explained
Photo by Viktor Talashuk / Unsplash

If it is your first time interacting with linux, the file structure may completely confuse you. Not to worry, we will be explaining each key aspect so you may understand and navigate linux directories with confidence.

Filesystem Hierarchy Standard

The Filesystem Hierarchy Standard (FHS) is a set of guidelines that define the directory structure and organisation of the file systems on Unix-like operating systems, (such as Linux). The FHS aims to ensure consistency and compatibility across different Unix and Unix-like systems, promoting interoperability and ease of use for both users and system administrators.

The FHS was first proposed in 1993 and has since been adopted by various Unix-like Operating Systems, including Linux distributions. The standard helps maintain a consistent directory structure, making it easier for users to navigate and locate files and directories across different systems. The FHS is now maintained by the Linux Foundation.

Key Points

  • All other directories and files appear under the root directory /, even if they are stored on different physical or virtual devices.
  • Most of the directories in this article exist on all Unix-like operating systems and are generally used in the same way, however some linux file systems may also contain additional directories that aren't set out by the standard.

Understanding this directory structure is essential for both beginners and experienced users, as it forms the foundation for organising and accessing files and directories. In this article, we'll delve into the key directories and their purposes.

Linux Directory Structure

The Root Directory ("/")

The root directory is the top-level directory of the Linux file system hierarchy. It is represented by a forward slash, /. All other directories, files, and devices are organised under the root directory. Only the root user has the ability to write to this directory.

Some may mistake this to be the equivalent of the C:\ drive on windows, however this is not the case as Windows can have multiple drives or partitions of different letters. As we stated earlier, all other "drives", directories and files on linux will be stored under the root directory, /, even if they are stored on different physical or virtual devices.

Essential Directories

1. /bin - Binary Executables

The /bin directory contains essential binary executables (commands) required for system boot, function and repair. These binaries are indispensable for basic system functioning and are available to all users.

2. /boot - Boot Loader Files

The /boot directory houses files necessary for the system boot process, such as the kernel and the GRUB boot loader's files.

3. /dev - Device Files

The /dev directory contains special device files representing physical and virtual devices connected to the system. The special files in this directory are not actually files, but they appear as files. Interacting with these files allows users to communicate with hardware components or virtual devices on the system.

This may confuse you but as stated in the Core Linux Principles, Linux stores everything as a file, even hardware.

An example of a virtual device in this directory would be /dev/null. This is a special device that disregards all input. This virtual device can come in handy as you can send files and strings here to destroy them.

4. /etc - Configuration Files

Configuration files for system-wide settings and applications are stored in the /etc directory. It's a critical directory for customising the system.

Note that this directory is only for system-wide configuration settings, user specific configuration settings will be found in the respective users home directory.

5. /home - User Home Directories

Each user on a Linux system has a home directory located under /home, for example, /home/bob. User-specific files and personal configurations are stored here.

Note that each user will only have access to their own home directory unless they have elevated permissions, such as being the root user.

6. /lib and /lib64 - System Libraries

The /lib and /lib64 directories contain essential shared libraries required by the binaries in the /bin and /sbin directories.

Libraries for binaries in the /usr/bin and /usr/sbin directories are located in the /usr/lib directory.

7. /media and /mnt - Mount Points

The /media directory is used as a temporary mount point for removable storage devices such as USB drives, SD cards, CD's etc. When this removable storage is inserted into your device, a directory for it is automatically made in the /media directory for you to access its contents.

The /mnt directory is similar to the /media directory except it is used by administrators to manually mount filesystems.

8. /opt - Optional Software

The /opt directory is usually reserved for storing and installation of optional software packages. It allows for the easy organisation of third-party applications.

9. /proc - Process Information

The /proc directory is a virtual file system that provides information about running processes and system info. Users can access and manipulate process-related data through files in this directory.

10. /root - Root User Home Directory

Not to be confused with the "root directory" /, this is the home directory for the root user. This is the administrative user's workspace, and it contains configuration files and settings specific to the root user.

Instead of being stored at /home/root like other users on the system, it is stored at /root.

11. /sbin - System Binaries

Similar to the /bin directory, /sbin contains binary executables. However, these binaries can only be run by the root or sudo user as they are typically meant for system administration tasks and are not intended for regular user use.  

12. /srv - Service Data

The /srv directory is designated for data used by services provided by the system. It simplifies the organisation of service-specific data.

For example if you were to run a HTTP server that hosted a website, you would store your website files within this directory.

13. /tmp - Temporary Files

The /tmp directory is used by the system, applications and even users to store temporary files that do not need to persist across reboots. Be careful not to store anything important here as the directory can also be cleared out at any time instead of only upon system reboots.

14. /usr - User Binaries and Libraries

The /usr directory contains user-related binaries, libraries, documentation, and source code. It is further divided into subdirectories like /usr/bin and /usr/lib.

This directory is read-only for standard users.

15. /var - Variable Files

The /var directory holds variable files, including logs, spool files, and temporary data generated by various system processes. It is crucial for maintaining system health and performance.

Unlike the /tmp directory, files stored here are not cleared automatically.

Conclusion

Understanding the Linux directory structure is fundamental for effective system administration and usage. Each directory plays a specific role in organising and managing files, and a clear comprehension of this hierarchy enhances the overall efficiency and functionality of a Linux system. Whether you're a novice Linux user or an experienced administrator, a solid grasp of the directory structure is a valuable asset in navigating and maintaining a Linux-based operating system.

Want to learn more about Linux?

You can learn more about Linux by checking out the recommended articles section below or by checking out our Linux Tag to view all of our Linux articles!