Skip to main content

Command Palette

Search for a command to run...

Linux File System

Published
16 min read
Linux File System

What is Linux File System?

A Linux file system is a structured collection of files on a disk drive or a partition. A partition is a segment of memory that contains some specific data. In our machine, there can be various partitions of memory. Generally, every partition contains a file system.

The general-purpose computer system needs to store data systematically so that we can easily access the files in less time. It stores the data on hard disks (HDD) or some equivalent storage type.

In Linux, the file system is generally a built-in layer of a Linux operating system used to handle the data management of the storage. It helps to arrange the file on disk storage. It manages the file name, file size, creation date, and much more information about a file.

Why Studying File System is Important?

Various computer science-related streams like DevOps, System Administration, Software Developer, Data Science and Cyber Security need a good understanding of the Linux operating system. Linux knowledge is valuable across a variety of industries and job roles.

while learning and understanding the Linux operating system, studying the Linux file system is crucial for users, administrators, and developers to manage and customize the system effectively, troubleshoot issues, and develop high-quality applications.

it helps users to navigate the file system efficiently, locate files and directories quickly, and understand how the system stores and manages files.

the file system enables users to customize the system by adding, removing, or modifying files and directories.

Developers need to understand the file system structure to create applications that interact with the file system correctly. Understanding the file system also helps developers to optimize their performance applications. also Knowing the file system structure can help users to diagnose and fix file system issues, such as disk space problems, corrupted files or directories, and permission issues.

How is Linux File System Structured?

In Linux, the file system is a hierarchical tree-like structure that is used to store, organize and access files and directories. The file system provides a way to access and manipulate data stored on storage devices like hard drives, flash drives, and network file systems.

The Linux file System starts from the root directory. The root directory is the top-level directory in the Linux file system hierarchy and is represented by the forward-slash ("/"). All other directories and files are located within this directory. The Linux file system uses a tree-like structure of directories that can be nested within each other.

Directories in the Linux file system include:

    • /bin

      • /boot

      • /dev

      • /etc

      • /home

      • /lib

      • /lost+found

      • /media

      • /mnt

      • /opt

      • /proc

      • /root

      • /run

      • /sbin

      • /snap

      • /srv

      • /sys

      • /tmp

      • /usr

      • /var

What do these directories do?

/bin

In Linux, most people prefer CLI (command line interface) over GUI (graphical user interface). In CLI the instructions to the computer are given using specific keywords in the terminal. Programs that define what these keyword instructions do are given in /bin directory.

The /bin directory in Linux is one of the most important directories in the system. It stands for "binary," and it contains a set of essential executable programs that are required for basic system operation and maintenance.

These binary programs are usually not only used by the system administrator but also by regular users. Some of the common programs located in the /bin directory include:

  • cat: used to concatenate and display files.

  • cp: used to copy files and directories.

  • ls: used to list the files and directories.

These programs are often referred to as "core utilities" and are usually included in every Linux distribution.

/boot

The /boot directory in Linux contains files and data that are necessary for the system boot process. Specifically, it contains the files and data required by the boot loader to start the operating system.

The boot loader is responsible for loading the kernel, which is the core of the operating system, into memory and passing control to it. The boot loader needs to know where to find the kernel and how to load it, and this information is stored in files located in the /boot directory.

The specific files and data stored in the /boot directory can vary depending on the specific Linux distribution and configuration but typically include:

  • The kernel image: This is the actual binary image of the kernel that is loaded into memory by the boot loader.

  • Initial RAM disk (initrd): This is a temporary file system that is loaded into memory along with the kernel image. It contains drivers and configuration files required to mount the root file system.

  • Boot loader configuration files: These files contain configuration information for the boot loader, including which kernel image to load and how to load it.

/dev

The /dev directory in Linux is used to represent and manage device files for all the hardware devices attached to the system, including hard drives, USB devices, network adapters, printers, and other hardware components.

the /dev directory is an important part of the Linux file system, as it provides a standard way to access and interact with hardware devices using device files.

Device files in Linux represent physical or virtual devices and allow users and programs to interact with them as if they were files. These device files are created dynamically by the kernel and stored in the /dev directory.

The /dev directory contains a variety of subdirectories and files, including:

  • /dev/null: This is a special file that discards all data written to it and returns end-of-file (EOF) when read from.

  • /dev/zero: This is a special file that returns an infinite sequence of null bytes (0x00) when read from.

  • /dev/random and /dev/urandom: These are special files that provide a source of random data for cryptographic purposes.

/etc

The /etc directory in Linux is used to store system-wide configuration files and settings for various applications and services running on the system. The name "etc" stands for "et cetera", which implies that it contains miscellaneous files and data that do not fit into other directories.

The /etc directory typically contains configuration files for various system services, such as networking, time synchronization, user authentication, printing, and more. These files can be edited by system administrators to customize the behavior of the system and its services.

Some examples of files that may be found in the /etc directory include:

  • /etc/passwd: A file containing user account information.

  • /etc/group: A file containing group information for users.

  • /etc/ssh/sshd_config: A file containing configuration settings for the SSH server.

/home

The home directory in Linux is a directory that is created for each user when they are added to the system. It is designated as the default location for a user's personal files and configurations.

The home directory is typically located at /home/username, where "username" is the name of the user. It contains various subdirectories and files that belong to the user, including:

  • Desktop: A directory containing the user's desktop files and shortcuts.

  • Documents: A directory containing the user's documents and files.

  • Downloads: A directory containing the user's downloaded files.

  • Various configuration files for the user's applications are stored in hidden directories such as .config and .local.

The home directory is designed to provide a private working area for each user, where they can store and organize their personal files and configurations. It also provides a level of security by isolating each user's files from other users on the system.

/lib

The lib directory in Linux is short for "library," and it contains shared libraries that are used by the operating system and various applications installed on the system. These shared libraries provide common functionality that can be used by multiple programs, thereby reducing the amount of duplicate code in the system and improving overall system efficiency.

Some examples of shared libraries that might be stored in the lib directory include:

  • libssl: A library that provides cryptographic functions for secure communication.

  • libxml2: A library that provides functions for parsing and manipulating XML documents.

Shared libraries are loaded into memory when a program that depends on them is run, and they remain in memory until they are no longer needed. This means that multiple programs can share the same copy of a library, which can help to reduce memory usage and improve system performance.

/lost+fond

The lost+found directory is a special directory in the Linux file system that is used by the file system checker (fsck) to store recovered files and directories that were previously lost or corrupted. When the file system is checked for errors during boot, fsck may encounter files or directories that are corrupted or have lost their link to the file system tree.

When fsck detects such issues, it attempts to recover the lost data and places it in the lost+found directory. The recovered files and directories are given unique names based on their inode number, and the owner and permissions are set to root.

The lost+found directory is typically located at the root of a file system, and each file system on a Linux system may have its own lost+found directory. It is important to note that the lost+found directory should only be accessed by the root user, as the recovered files and directories may contain sensitive data that could be accessed by unauthorized users.

/media

The /media directory in Linux is used as a mount point for removable media such as USB drives, CDs, and DVDs. When a removable device is connected to the system, the operating system automatically detects it and creates a subdirectory under /media for the device to be mounted.

For example, if you connect a USB drive to your Linux system, the system will create a directory such as /media/usb0 or /media/username/usb0 (depending on the configuration) where the USB drive can be accessed.

Once a device is mounted in the /media directory, its contents can be accessed just like any other file or directory on the system. When the device is removed, the subdirectory for the device is automatically removed from the /media directory.

In addition to providing a convenient way to access removable media, the /media directory also helps to maintain

consistency across different Linux distributions. This is because most Linux distributions follow the Filesystem Hierarchy Standard (FHS), which specifies that removable media should be mounted in the /media directory.

/mnt

The /mnt directory in Linux is used as a mount point for file systems that are temporarily mounted. This includes file systems such as network file systems, external hard drives, or disk images.

In contrast to the /media directory, which is used for mounting removable media, the /mnt directory is used for mounting file systems that are not intended to be removed while the system is running. This means that the contents of the /mnt directory are typically mounted manually, and are not automatically detected by the operating system.

The use of the /mnt directory is a convention that has been adopted by many Linux distributions, although it is not part of the Filesystem Hierarchy Standard (FHS) that defines the directory structure for Linux systems. Instead, the FHS recommends using subdirectories of the /mnt directory for temporary mounts.

/opt

he /opt directory in Linux is used to store optional or third-party software applications that are not included in the standard system installation. This directory provides a location where software vendors can install their applications without interfering with the standard system directories or other applications.

By keeping optional or third-party software applications separate from the standard system directories, the /opt directory helps to maintain the overall stability and security of the system. It also provides a centralized location where users can find and manage these applications.

/proc

The /proc directory in Linux is a virtual file system that provides information about the system and running processes. It is a special type of file system that does not contain actual files, but rather provides a way for applications and the kernel to communicate and exchange information.

Each file and subdirectory in the /proc directory represents a system resource, such as a process, a device, or a kernel configuration parameter. For example, the /proc/cpuinfo file provides information about the system's CPU, including its speed, number of cores, and vendor.

One of the most useful features of the /proc directory is its ability to provide real-time information about running processes. The /proc directory contains a subdirectory for each running process, named after the process ID (PID). Inside this directory, there are files that provide information about the process, such as its memory usage, open files, and environment variables.

The information provided by the /proc directory can be accessed and read by both system administrators and applications. Many system monitoring and performance analysis tools use the information provided by the /proc directory to gather data about the system and its processes.

/root

The /root directory in Linux is the home directory for the root user. Unlike other user home directories, which are located in the /home directory, the root user's home directory is located in the top-level file system directory.

The /root directory is used to store configuration files and other data specific to the root user.

The root user's home directory is typically not accessible by other users, except for the system administrator or superuser. This is because the root user has complete control and access to all files and directories in the system, and allowing other users to access the /root directory could pose a security risk.

/run

The /run directory in Linux is a temporary file system that is used to store runtime data for system processes. It is commonly referred to as the "run-time directory" or "run directory".

The /run directory is typically used to store system-level data that needs to be accessed quickly and frequently. For example, network interface configuration files (/run/network/) and process ID files (/run/lock/) are stored in the /run directory.

One of the benefits of using the /run directory is that it is a tmpfs file system, which means that it is stored in memory rather than on disk. This makes it faster and more efficient than traditional file systems, which are stored on disk.

/sbin

The /sbin directory in Linux is similar to the /bin directory, in that it also contains executable programs. However, the programs in /sbin are typically used only by the system administrator for system maintenance and management tasks, rather than by regular users.

The programs in /sbin are often called "system binaries" and typically require elevated privileges to execute. They are used for tasks such as:

  • System startup and shutdown

  • Disk and file system management

  • Network management and configuration

  • System backup and recovery

  • Hardware management and configuration

Some examples of programs located in the /sbin directory include:

  • ifconfig: used to configure network interfaces

  • init: the first process started during system boot

  • reboot: used to restart the system

The main difference between the /bin and /sbin directories in Linux is the intended audience for the executables stored in each directory.

The /bin directory contains essential binary programs that are used by both system administrators and regular users. These programs are often referred to as "core utilities" and are required for basic system operation and maintenance.

On the other hand, the /sbin directory contains system binaries that are typically used only by the system administrator for system maintenance and management tasks. These programs often require elevated privileges to execute and are not intended for use by regular users.

/snap

The /snap directory in Linux is used to store snap packages, which are self-contained, universal software packages that can run on any Linux distribution that supports snaps. Snap packages are designed to simplify software installation and distribution on Linux systems by bundling all the necessary dependencies, libraries, and configuration files into a single package.

Snap packages are installed and managed using the snapd daemon, which runs in the background and provides an interface for managing snap packages. When a snap package is installed, it is mounted as a read-only file system in the /snap directory.

The /snap directory is organized by snap package names and versions, and each package is installed in its own subdirectory. Each subdirectory contains a current symlink, which points to the current version of the snap package, as well as other files and directories that are specific to the package.

/srv

The /srv directory in Linux is used to store data for services provided by the system. It is intended to hold site-specific data that is served by the system, such as web server content, FTP files, and other data related to network services.

The /srv directory is not used by the system itself, but rather by applications and services that are installed on the system. For example, a web server may store its web content in the /srv/http directory, while an FTP server may store its files in the /srv/ftp directory.

The purpose of the /srv directory is to separate the system's configuration and runtime data from the data that is served by the system. This makes it easier to manage and back up the system since the configuration and runtime data is stored separately from the site-specific data.

/sys

The /sys directory contains information about hardware devices, such as CPU, memory, disks, network interfaces, and USB devices. It also provides information about the system's power management settings, kernel modules, and device drivers.

One of the key uses of the /sys directory is for device management. Device files for hardware devices are located in the /dev directory, but the information about those devices is stored in the /sys directory. System administrators can use the /sys directory to view and modify device settings, such as device speed, power usage, and other hardware parameters.

In addition, the /sys directory is used for system debugging and troubleshooting. System administrators can use the files and directories in the /sys directory to diagnose hardware and kernel-related issues.

/temp

The /tmp directory in Linux is used to store temporary files that are created by the system and by applications. These files are typically deleted when the system is rebooted, or when the application that created them exits.

The /tmp directory is a common location for programs to store temporary files, such as log files, backups, and cache files. It is also used by the system to store temporary files that are created during system boot or system maintenance.

The purpose of the /tmp directory is to provide a centralized location for storing temporary files, so that they do not clutter up the user's home directory or other system directories. This makes it easier for system administrators to manage disk space and keep the system running smoothly.

One important thing to note is that because the /tmp directory is typically cleaned out when the system is rebooted, it should not be used to store important data that needs to be preserved between reboots.

/user

The /usr directory in Linux is used to store user-related data and programs that are not necessary for the system's basic operation. The name "usr" stands for "Unix System Resources".

The /usr directory typically contains a variety of subdirectories, including:

  • /usr/bin: A directory containing binary executable files for user applications and utilities.

  • /usr/sbin: A directory containing binary executable files for system administration utilities.

  • /usr/lib: A directory containing shared libraries and other architecture-independent files used by programs in /usr/bin and /usr/sbin.

  • /usr/local: A directory containing user-installed applications and libraries that are not part of the operating system distribution.

  • /usr/src: A directory containing source code for various software packages installed on the system.

/var

The /var directory in Linux is used to store variable data files, such as log files, spool files, and temporary files that are expected to grow in size over time.

Here are some examples of the types of files that are typically stored in the /var directory:

  • Log files: Many programs write log files to the /var/log directory, including system logs, application logs, and web server logs. These log files can be used for troubleshooting and monitoring the system.

  • Spool files: The /var/spool directory is used to store spool files for various services, such as printing and email. For example, print jobs that are sent to a printer are stored in the /var/spool/cups directory until they are printed.

  • Temporary files: Some programs may create temporary files in the /var/tmp directory, which are expected to persist across reboots.

  • Package files: When new software packages are installed on the system, their files are often stored in the /var/lib directory.

  • Cache files: Some applications may store cache files in the /var/cache directory, which can be used to speed up performance.

The /var directory is designed to be used for files that are expected to change in size over time, which is why it is often located on a separate partition from the root (/) directory. This helps prevent the root file system from filling up with log files and other variable data, which could cause the system to become unstable.

What’s Next?

The most commonly used file system in Linux is the ext4 file system, although there are other file systems available such as Btrfs, XFS, and ZFS.

Click Here to Learn more

G

love it 🔥

L

Great blog!

1