Understanding Linux File System: An Overview of Essential Directories
Tags: linux, devops, opensource
Published: 2023-04-22 12:20:30

## Introduction

The Linux operating system has a special component called the file system, which helps store and access files and data. It has a hierarchical structure that helps keep things organized and standardized. Knowing how this hierarchy works is important for anyone using Linux so they can find what they need quickly and easily. In this blog post, we'll go over each folder in the Linux file system hierarchy and explain what they're used for. By the end, you'll have a better idea of how the Linux file system works and how to navigate it.

## Linux File System

The Linux file system is structured hierarchically, with a single root folder `/` as the starting point for all directories and files. Within the root folder, there are various directories, including `/bin`, `/home`, `/usr`, and `/var`, among others. Every user on Linux gets their own space inside the `/home` directory, making it easier to organize and access personal files. In addition, each user has its own space for system configuration files and settings, which helps to prevent conflicts between users. Programs installed system-wide are available to all users, ensuring that everyone has access to the same tools and resources.

![Image of root (/) directory](https://cdn.hashnode.com/res/hashnode/image/upload/v1682126094337/dfb41e1e-3fb6-4c7a-80d4-1861b359df2b.png)

On the other hand, the Windows file system has multiple root folders, with each drive letter (such as `C:\` or `D:\`) serving as a separate root folder. Within each root folder, there are various directories, such as Program Files, Users, and Windows, among others. Unlike Linux, Windows does not have a single root folder that serves as the starting point for all directories and files. Each user on Windows also gets their own space, typically located in the Users directory, which includes personal files, documents, and settings.

In Linux, the root directory `/` is where all other directories and files stem from, and it includes important directories like `/home`, `/root`, `/bin`, `/sbin`, `/dev`, and others. Understanding the meaning of these directories is essential for navigating the Linux file system efficiently.

## Directories

### /home

The `/home` directory in Linux is where all non-root user home directories are stored. Each user has a folder in this directory with their name as the folder name.

![Image of /home directory](https://cdn.hashnode.com/res/hashnode/image/upload/v1682126156865/c1a043bb-0f1f-47a0-90d3-3a7065225231.png)

Any programs installed in the `/home` directory is available only to the user associated with that directory. This allows each user to have their own set of programs and applications without interfering with other users' settings.

Another important thing about the `/home` directory is that you can read and write to it without needing root access.

### /root

The `/root` directory in Linux is the home directory of the root user. Unlike the `/home` directory which contains home directories of non-root users, the `/root` directory is specifically for the root user. It's important to note that this directory is not the same as the root directory `/`, which is the starting point for all directories and files in the Linux file system.

### /bin

The `/bin` directory in Linux stands for "binaries" and it contains the essential executable files (commands) for most user commands like `ls`, `cat`, `pwd`, and `touch`.

![Image of /bin directory](https://cdn.hashnode.com/res/hashnode/image/upload/v1682125063777/41230d46-74d1-42b7-af14-a0c3acf9f6c8.png)

These executable files are available system-wide, meaning all users can access them. The reason why they are stored in the `/bin` directory is that they are binary files that the computer can understand, hence the name "binaries."

Having these essential commands available in the `/bin` directory, users can quickly access them and perform common tasks efficiently.

### /sbin

The `/sbin` directory in Linux stands for "system binaries" and it contains essential commands related to the system. These commands are used by system administrators for tasks like setting up users, networks, and passwords.

![Image of /sbin directory](https://cdn.hashnode.com/res/hashnode/image/upload/v1682126264324/c47a7c0b-41fc-473d-b009-392cba8ffe73.png)

Since these tasks require administrative privileges, you need superuser permissions to execute commands in the `/sbin` directory. These binaries are considered essential for system maintenance and are not available to regular users.

Overall, the `/sbin` directory contains critical system binaries that system administrators use to manage and maintain the Linux system.

### /lib

The `/lib` directory in Linux stands for "library" and it contains essential shared libraries that are required by executables in the `/bin` and `/sbin` directories.

In Linux, a program is often split into multiple components, with the executable files stored in the `/bin` or `/sbin` directories and the necessary libraries stored in the `/lib` directory. This separation allows programs to be more modular and efficient.

![Image of /lib directory](https://cdn.hashnode.com/res/hashnode/image/upload/v1682126315038/503cea3c-d42b-46ae-8ec6-d294b1915192.png)

All programs downloaded on Linux are stored in this way, with their binaries in the `/bin` directory and their libraries in the `/lib` directory. The `/lib` directory is an important component of the Linux file system that ensures that programs can run efficiently and with the necessary resources.

### /usr

The `/usr` directory in Linux stands for "user". It originally contained home directories but now it contains the `/bin`, `/sbin`, and `/lib` folders. The bin folder contains commands like `ls` and `copy` that is executed from the terminal.

![Image of /usr directory](https://cdn.hashnode.com/res/hashnode/image/upload/v1682126385556/d6bf7a05-5d76-46b4-bc0a-3e32de6c5fe5.png)

The separation of binary files in both the root and user binary folders is due to limitations in storage space in the past. Though this limitation no longer exists, the concept remains the same. Some Linux OS versions have fewer commands in the root `/bin` and `/sbin` directories.

### /usr/local

The `/usr/local` directory in Linux contains the `/bin`, `/sbin`, and `/lib` folders, and it's where third-party applications are installed. When a user installs a program on their computer, its binaries go into `/usr/local/bin`, and its libraries go into `/usr/local/lib`. This directory is available to all users on the computer, and any program installed here can be accessed system-wide.

![Image of /usr/local directory](https://cdn.hashnode.com/res/hashnode/image/upload/v1682126406503/89c764c6-1faf-485c-871b-77880c570285.png)

### /opt

The `/opt` directory in Linux stands for "optional" and is initially empty. It is used for programs that do not split their components like binaries and libraries.

These programs are typically third-party programs that we install on our system. Code editors and browsers are some examples of programs that are installed in `/opt`. Programs installed in `/opt` are available system-wide, just like those installed in `/usr/local`.

However, it is important to note that programs that can split their components are typically installed in `/usr/local`, whereas those that cannot are installed in `/opt`.

### /boot

The `/boot` directory in Linux contains the essential files required for booting the operating system. These files include the Linux kernel, initial ramdisk image, bootloader configuration files, and other boot-related files.

![Image of /boot directory](https://cdn.hashnode.com/res/hashnode/image/upload/v1682126713114/8691d3f8-7be6-4103-b847-09e518a130b2.png)

This directory is crucial for the proper functioning of the operating system and should not be modified or deleted by the user. The files in this directory are automatically updated during system upgrades and kernel updates.

### /etc

The `/etc` directory in Linux stands for "et cetera" and is the location where system configurations are stored, including Linux user data and passwords, network settings, and other important system information. It is a read-write directory and has emerged as the main configuration location for various Linux distributions.

### /dev

The `/dev` directory stands for "devices" and contains device files for hardware such as webcams, keyboards, hard drives, and microphones. Applications and drivers access this directory, not users. All files the system needs to interact with hardware will be found here. In other words, it is a location of special files that represent hardware devices installed on the system. The files in this directory are generally not directly readable or writable, but the system uses them to interact with hardware.

### /proc

The `/proc` directory in Linux is a virtual file system that provides a way for users and programs to access system information. It does not contain physical files, but instead, the files within it are created dynamically and reflect the current state of the system.

Users and programs can read and write to these files to get information about system hardware, processes, and kernel settings. For example, the `/proc/cpuinfo` file provides details about the system's CPU usage, while the `/proc/meminfo` file contains information about memory usage.

Overall, the `/proc` directory is a critical component of the Linux system and is used extensively by system administrators and programmers for debugging, monitoring, and system analysis.

### /sys

The `/sys` directory in Linux is a special file system that offers a structured view of kernel data structures and hardware device information. It is presented in a hierarchical manner of directories and files, allowing easy access and modification of device parameters.

The directory contains crucial details of system devices like input/output (I/O) devices, network interfaces, and storage devices. Additionally, it holds information regarding system status, including power management settings and system clock configurations.

It is different from the `/proc` directory, `/sys` provides information about the hardware and drivers in a structured and standardized way, whereas the `/proc` directory provides information about the system's processes and kernel more systematically. The `/sys` directory is used by system administrators and device driver developers to interact with the system's hardware and configure the system's devices.

### /var

The `/var` directory in Linux stands for "variable". It contains files and directories that may change in size and content over time during the system's operation. The `/var/log` directory stores system log files, while the `/var/cache` directory contains cached data from application programs.

![Image of /var directory](https://cdn.hashnode.com/res/hashnode/image/upload/v1682126464016/a685e478-1cf0-4d87-8893-b074ed0c1ba3.png)

Other directories in `/var` may include spool directories for printing and mail, and directories for temporary files created by applications. These files are typically read and written by system services and applications, rather than users directly.

### /run

The `/run` directory in Linux is a temporary file system that stores runtime data of processes running on the system. It is used by system services to store data that needs to be preserved across reboots. The data stored in `/run` is lost when the system is shut down.

This directory was created to replace the `/var/run` directory which is used to store volatile runtime data. The files in the `/run` directory are created by the system at boot time and are automatically cleaned up on shutdown. Some of the files stored in `/run` include process IDs, socket files, and lock files.

### /tmp

The `/tmp` directory in Linux is used to store temporary files that applications create during their operation. These files are usually deleted automatically at some point, as they are not meant to persist beyond the current session. The `/tmp` directory is accessible by all users, and applications typically use it to store data that does not need to be kept long-term.

### /media

The `/media` directory in Linux is used to mount removable media devices such as USB drives, CD-ROMs, and DVDs. Whenever a new removable media device is inserted into the computer, a corresponding directory will automatically be created in `/media`, and the contents of the device will be accessible inside the directory. This directory is used by the system to automatically mount and unmount the removable media.

### /mnt

The `/mnt` directory is used for temporarily mounting file systems. It is usually empty but can be used by system administrators to manually mount file systems as needed. Unlike the `/media` directory which is used for automatically mounting removable media devices, the `/mnt` directory is used for manually mounting file systems.

## Hidden files

Hidden files are files that are not shown in the directory listing by default. These files are often used to prevent important data from being accidentally deleted or to store auto-generated files or configuration settings that are specific to a particular user.

![Image of Hidden Files](https://cdn.hashnode.com/res/hashnode/image/upload/v1682126469398/a658f495-829f-411f-bd0d-83a7abef56c0.png)

In Linux, hidden files are denoted by a dot (`.`) preceding the file name, and are often referred to as "dotfiles". When we enable the option to show hidden files, we can view these files and modify them as needed. It is important to be aware of the presence of hidden files, as they can contain critical information related to the functioning of the system or specific applications.

## Conclusion

In conclusion, although users may not typically interact with the various directories on a Linux system, it is important to understand their purpose and location. Applications installed using package managers or installers automatically handle the creation of folders, binaries, and libraries. For example, the insertion of a USB device will automatically create a directory in `/media`. Knowing where these files are located and how the system works can be beneficial for troubleshooting purposes.