- 8777701917
- info@saikatinfotech.com
- Basirhat W.B
Linux Filesystem follows a tree-like hierarchical layout that is governed by the Filesystem Hierarchy Standard (FHS). This is a standard maintained by the Linux Foundation. The latest version of the FHS at the time of writing this guide is version 3.0.3 which was released in June 2015.
The Linux Filesystem structure starts at the very top with the root directory which is the uppermost directory in the hierarchy. It contains all the directories and subdirectories on the system as we shall see later on in this guide.
To get a better picture of this, navigate to the root directory /
and run the following command:
The output provides all the main directories residing on the system. Before we delve deeper and explore what each of these directories contain, let us briefly look at the main types of files on a Linux system.
In Linux and UNIX systems, everything is considered a file. If not, then it’s a running process. Generally, all files in Linux fall into either of these three categories.
That said, let us now examine the Linux File System Tree in more detail.
Denoted by a single forward slash ( / ), the root directory is the topmost directory in the Linux hierarchy structure, as discussed earlier. All files and folders on your Linux system are stored here and can be referenced from this directory, even when stored in various locations such as removable or virtual devices.
NOTE:
The root (/) directory is not to be confused with the root home directory ( /root ).
The /home
directory is a directory that contains users’ personal files. The directory is the entry point for any login user on the Linux system. It stores folders, files, and personal data that is specific to an individual user.
Folders in the /home
directory take the form /home/USERNAME
where USERNAME
is the name of the login user. For example, if we have a login user called mike, the home directory for the user will be /home/mike
.
Inside the /home/USERNAME
directory are other sub-directories such as Desktop, Downloads, Documents, Pictures, Videos, Templates, Public, and Music as below.
In addition, home directories contain personalized configuration files which are hidden files preceded by a dot. Such files include the .bashrc
, .bash_logout,
and .bash_profile
to mention a few. To view hidden files, run the ls
command with the -la
option as shown.
This is the home directory of the root account, also known as the root user’s home directory. The /root
directory stores configuration files for the root account in the same way each regular user’s home directory contains configuration files and regular files for that user.
Another critical directory is the /boot
directory. The directory, as the name implies, contains essential files needed to successfully boot the system. These files include the grub bootloader files, root filesystem files, Linux kernel files (vmlinuz), and other boot configuration files
The /bin
directory contains binary executables or Linux programs. These include common Linux commands that are made available for all users in single-user mode. These include cat, chown, chmod, ping, cp, mkdir, ls, cat, rm, and mv just to mention a few.
To confirm the path of a binary executable or command such as the cp
command, run the command:
Unlike the /bin
directory, the /sbin
directory contains binary executables and command line tools that are preserved for the root user. These are privileged commands used for system administration tasks. Examples of such commands include fdisk, route, reboot, mkfs, init, and fsck to mention a few.
Again, to confirm the path to the binary executable, run the which
command followed by the binary executable.
The /dev
directory contains special files that are representative of devices attached to the system. These include consoles, hard drives, or any other peripheral devices plugged into the system. A good example of a device file is /dev/sda
which represents the first SATA hard drive attached to the Linux system.
The /dev
directory is also a storage location for pseudo devices or virtual devices that do not reference any hardware connected to the system. An example is the /dev/null
file which discards any data sent to it.
The /etc
directory contains host-specific system-wide configuration files. It stores configuration files required by all programs as well as startup and shutdown shell scripts.
The configuration files can be modified using a text editor such as nano or vim by the root or sudo user which is a regular user with elevated privileges to run certain root commands.
The /lib directory contains shared library images required in the /bin
or /sbin
directories. These are essential libraries required by the system to boot and run normally.
The /media
directory contains temporary sub-directories on which removable media such as optical drives are automatically mounted. A good example of a sub-directory is /media/cdrom
for optical drives.
The /mnt
directory provides a temporary mount point on which removable media such as CDROMs can be mounted. It is most often used to mount storage devices or partitions manually, and is more of a relic of the past.
On Linux systems, temporary files are stored in the /tmp
directory. These are temporary files created by the system and users. Files in this directory are usually a few kilobytes in size and are, in most cases, deleted when a system is rebooted.
The /opt
directory contains add-on applications or software packages that are provided by a third-party vendor and are not installed through your operating system package manager. Each such application has its own subdirectory which contains all the essential files needed for it to run.
When you install a software package from a third-party repository, or compile software binaries yourself, the files are stored in the /opt
directory.
Var stands for variable. As the name suggests the /var
directory is a directory that contains files that are constantly changing in size such as log and spool files.
Here is a list of the salient directories contained in the /var
directory:
/var/log
– Contains system and application log files.
/var/cache
– Contains cached data from programs.
/var/mail
– Contains users’ mailboxes
/var/spool
– Comprises queued or spooled files for various programs.
/var/spool/cron
– Contains spooled files for cron jobs.
/var/spool/at
– Contains spooled jobs for at.
/var/spool/lpd
– Contains spooled files for printing.
/var/opt
– Contains variable data files for the /opt
directory.
Most Linux distributions come with the /run
filesystem. This is a directory that stores volatile runtime data since the system was started. Data stored in this directory does not persist upon a reboot.
Also referred to as the proc filesystem, The /proc
directory is a virtual or pseudo filesystem that contains special files that provide information about running processes and the kernel’s current state. It is regarded as the information and control center of the Linux kernel.
The proc directory is a peculiar directory in that it’s not a real filesystem and it ceases to exist once the system is powered off. It is mounted at the /proc
mount point during the booting process.
This is one of the most critical directories in the Linux system. The /usr
directory is a directory that comprises libraries, binaries, and documentation for installed software applications. System files contained in this directory are shareable among other users.
At a glance, here are some of the salient subdirectories contained in the /usr
directory:
/usr/bin
– This contains binary files for user programs that cannot be found under the /bin
directories. Examples of such programs include less, more, scp, and awk to mention a few.
/usr/sbin
– This provides binary files for system administrators or privileged users. Usually, system binaries are located in the /sbin
directory but if you can’t find them there, look under the /sbin
directory.
/usr/local
– The directory contains user programs installed from source or outside the distribution’s provided software. For example, when you install the Go programming language from source, it goes under the /usr/local/go
directory.
/usr/lib
– This provided libraries needed by the /usr/bin
and /usr/sbin
directories.
/usr/src
– This contains the Linux header files, kernel sources, and documentation.
The term srv stands for service. The/srv
directory contains site-specific data for your Linux distribution. It points to the location for data files for a specific service such as www, rsync, FTP and CVS.
This is a virtual or pseudo filesystem that contains a collection of virtual files that are attached to the Linux Kernel.
This is where snap packages go into. Snap is a package management system developed by Canonical, the publisher and maintainer of Ubuntu. Snaps are containerized, cross-distribution software packages that are packaged with all their dependencies. They are easy to install and are intended to work across all major Linux distributions that have snap enabled.
If you have installed an application from a snap package, then all the software files will be found in the /snap
directory.
This is a directory that is mostly found in Ubuntu and Ubuntu-based distributions. It’s a special directory that contains obsoleted data. These are fragments of files that have either been deleted or lost during disk operation.
The Linux filesystem is a hierarchical directory structure used by the operating system to store and organize files. It is built on a tree structure where the root directory (denoted as /
) is at the top, and all other files and directories branch off from it. Here’s an overview of the main components of a typical Linux filesystem:
/
)/bin
: Contains essential binary executables (programs) required for the system to function. These are often required for troubleshooting, as they are available even when other filesystems are not mounted.
ls
, cp
, mv
/boot
: Contains bootloader files and kernel-related files necessary for starting the system. This includes files like the kernel image (vmlinuz
) and the bootloader configuration (grub
).
vmlinuz
, grub/
/dev
: Contains device files, which represent hardware and virtual devices on the system. Each device, like a hard drive or USB stick, is represented by a file here.
/dev/sda
, /dev/tty0
/etc
: Contains system-wide configuration files and scripts for configuring the system and applications.
/etc/passwd
, /etc/fstab
/home
: The directory where user-specific files and directories are stored. Each user on the system has a subdirectory under /home
(e.g., /home/user1
, /home/user2
).
/home/john
, /home/admin
/lib
: Contains shared libraries and kernel modules required to run programs stored in /bin
and /sbin
. These are essential for system operations.
/lib/x86_64-linux-gnu/
/media
: This is where removable media such as USB drives, CD-ROMs, and external hard drives are mounted automatically.
/media/usb
, /media/cdrom
/mnt
: A temporary mount point used for mounting filesystems. Often used by system administrators to mount filesystems manually for maintenance or other tasks.
/mnt/data
/opt
: Used for installing optional or third-party software. This directory is typically used for large applications or packages that don’t conform to the standard Linux filesystem hierarchy.
/opt/google/chrome
/proc
: A virtual filesystem that contains runtime information about the kernel and processes. It does not correspond to actual disk storage but provides insight into system and process states.
/proc/cpuinfo
, /proc/meminfo
/root
: The home directory of the root user (superuser). Unlike /home
, which stores regular user directories, /root
is dedicated to administrative tasks.
/root/
/run
: Contains runtime data, such as information about the system’s state, services, and temporary files that should not persist across reboots.
/run/user/
/sbin
: Contains system binaries required for system administration tasks. These programs are typically executed by the system administrator (root).
ifconfig
, shutdown
, fsck
/srv
: Contains data for services provided by the system. This could include files served by a web server, FTP server, or other services.
/srv/www/
/sys
: Another virtual filesystem that provides information and controls for the kernel, such as hardware details, system status, and device management.
/sys/class/net/eth0
/tmp
: A temporary directory used by programs to store temporary files. Files in this directory are usually deleted when the system reboots.
/tmp/file123
/usr
: Contains user-related programs, libraries, and documentation. This is the largest directory on most systems and is further divided into subdirectories like /usr/bin
for executable files, /usr/lib
for libraries, and /usr/share
for shared data.
/usr/bin/bash
, /usr/lib/python3/
/var
: Contains variable files, such as logs, databases, email, and spool files. Files in /var
change frequently and can grow in size.
/var/log/
, /var/mail/
Linux supports different types of filesystems, which can be mounted in various directories. Some common filesystem types include:
Each file and directory in the Linux filesystem has associated permissions that control who can read, write, or execute them. These permissions are granted to three types of users:
Permissions are typically displayed using a string like rwxr-xr-x
, where:
r
= read permissionw
= write permissionx
= execute permissionThe Filesystem Hierarchy Standard (FHS) is a specification that defines the directory structure and directory contents in Linux systems. It provides a consistent structure across distributions, making it easier for users and administrators to understand where files are located.
The Linux filesystem is designed to be highly modular and flexible, with different directories serving specific purposes. It is important for both system administrators and users to understand the structure in order to effectively manage the system.
The Linux file system is a method of organizing and managing files on a Linux-based operating system. It defines how to store, access, and retrieve data on the disk. Files are arranged in a hierarchical directory tree starting with the root directory (/
), which branches into subdirectories and files.
Linux supports various file system types, such as ext4, XFS, Btrfs, and ZFS, each offering different features like journaling, scalability, and snapshot capabilities. The most commonly used file system on Linux is ext4, known for its balance between performance and reliability.
Linux has evolved from the limited Minix system to more advanced options like ext, ext2, and ext3. Each version improved file management and storage capabilities, with ext3 adding journaling for better data integrity.
Today, ext4 is the default Linux file system, offering faster performance, larger file support, and improved reliability for modern usage. The following graph shows the ext4 system evolution:
The key directories in Linux include:
File permissions and ownership are critical for security. They allow control over which users can read, write, or execute files and ensure efficient data management across various environments.
Linux supports a variety of file system types, each suitable for different use cases, ranging from general-purpose desktop environments to large-scale enterprise storage solutions. Using the appropriate file system optimizes performance, reliability, and data management.
The table below outlines key Linux file systems, their main features, advantages, and common applications:
File System | Use Case | Features | Main Pros/Cons |
---|---|---|---|
ext4 | Default on most Linux distributions. Suitable for general-purpose systems, including desktops and servers. | Journaling for crash recovery. Support for volumes up to 1 EiB and files up to 16 TiB. Fast mount times and delayed allocation for better performance. | Mature and stable with extensive community support. Lacks advanced features like snapshots. |
XFS | Ideal for high-performance environments that handle large files, such as media servers or databases. | High throughput with large files and scalable to massive storage. Good support for parallel I/O operations. Online defragmentation and resizing. | Poor performance with many small files. Complex to tune and manage effectively. |
Btrfs | Used for advanced use cases that require snapshots, subvolumes, or integrated volume management; often found in modern servers and storage appliances. | Snapshotting, RAID support, self-healing via checksums. Support for compression and deduplication. Online resizing and defragmentation. | Less mature than ext4. Stability issues in certain use cases. |
ZFS | Suitable for environments that require extreme data integrity, such as enterprise servers, backups, and NAS devices. | Combines file system and volume management. RAID-Z, data deduplication, and end-to-end data integrity verification. Supports pools with immense storage capacities. | Requires substantial memory for optimal performance (8 GB+). Licensing restrictions (CDDL vs. GPL). |
exFAT & NTFS (via ntfs-3g) | Typical choice for dual-boot setups or external drives shared between Linux and Windows. | Read/write support for NTFS and exFAT partitions on Linux. exFAT is optimized for flash drives and SD cards. NTFS supports advanced Windows-specific features. | ntfs-3g performance can be slower compared to native NTFS on Windows.exFAT does not support journaling, which limits data recovery options. |
The Linux file system structure is hierarchical, starting from the root directory (/
) and branching into subdirectories like /bin for binaries, /etc for configuration files, and /home for user data. Unlike Windows, Linux uses a unified directory structure, with additional storage devices mounted within this hierarchy.
The system manages files and directories through inodes, which store metadata like permissions and ownership. Additionally, Linux stores everything as a file, including directories, printers, partitions, kernel data, etc. The file permissions model thus ensures secure and efficient management of files across different users and environments, from desktops to large-scale servers.
Linux file systems offer a range of features that optimize performance, security, and data integrity. Below are the key features that define the functionality and reliability of Linux file systems:
Modern Linux file systems such as ext4 and XFS support journaling, which helps protect against data corruption in case of a system crash or power failure. Journaling records modifications and ensures data consistency and quick recovery after sudden shutdowns.
The following graph shows some key features of the ext4 file system, one of the most widespread file system types in Linux:
Linux uses a robust permissions model to control file access. Each file has an owner, group, and permission settings (read, write, execute) for the owner, group, and others. This system enforces security across multi-user environments and protects sensitive data from unauthorized access.
Linux allows users to mount different file systems into a single unified directory structure. Users can mount devices, partitions, and network shares at any point in the directory tree. Such a system provides flexibility in organizing and accessing storage.
An inode is a data structure that stores file metadata, including permissions, ownership, and timestamps. Each file and directory is associated with an inode, which helps the system manage file information efficiently.
Advanced file systems like Btrfs and ZFS support snapshots, which create point-in-time file system copies. These snapshots serve as backups, data recovery, and version control without affecting system performance.
File systems like XFS and ZFS easily handle large volumes and files, making them suitable for environments with massive storage needs. They support high scalability, ensuring performance remains stable as the file system grows.
Btrfs and ZFS offer built-in compression and deduplication features. They allow more efficient storage space use by reducing redundancy and compressing data on the fly.
Mounting in Linux refers to making a file system accessible at a specific directory within the system’s directory tree. This process is crucial for managing multiple storage devices, partitions, or network shares. Read the sections below to learn the key concepts and steps involved in mounting file systems on Linux.
A mount point is a directory where the system attaches an additional file system. For example, a separate partition can be mounted at /mnt/data, allowing access to its contents from this directory. Any directory can be used as a mount point, and multiple file systems can be mounted across different locations within the directory tree.
The mount command allows users to mount additional file systems to a certain mount point on the currently accessible file system. The command syntax is:
mount -t [type] [device] [dir]
The command passes the mount instructions to the kernel, which completes the operation. For example:
sudo mount /dev/sdb1 /mnt/media
The command above mounts the /dev/sdb1
file system to the /mnt/media
directory.
Linux uses the /etc/fstab configuration file to mount file systems on boot automatically. The file contains instructions on where to mount which devices, along with information on the file system type and mount behavior. Below is an example entry in the /etc/fstab file:
/dev/sdb1 /mnt/data ext4 defaults 0 2
The entry above instructs the system to mount the file system at /mnt/data every time the system starts.
Various options are available to control system behavior during file system mounting. These options can be added via the mount
command or configured in /etc/fstab. Some common mount options include:
ro
. Mounts the file system as read-only and prevents write operations.rw
. Mounts the file system with read and write permissions (default).noatime
. Disables the update of access time on files, improving performance.nosuid
. Blocks the execution of setuid
and setgid
bits to enhance security.nodev
. Prevents device file interpretation to improve security on non-root file systems.Use the umount
command to disconnect a file system safely. The command detaches the file system after all pending read/write operations are complete. The syntax is:
sudo umount [device/dir]
Unmounting is necessary before removing a storage device or making system changes to avoid data corruption.
Despite the robust and flexible nature of Linux file systems, each has certain limitations. These limitations vary depending on the file system type and use case. Below are some common limitations across various Linux file systems.
Each file system has its maximum volume and file size limits. For example, ext4 is sufficient for most users when it comes to file and volume size limits but may not be enough for environments handling extremely large datasets.
XFS and ZFS offer higher limits, but even these systems have practical constraints on scalability in certain scenarios.
The table below provides a comparison of sizing limits for common file systems:
File System | Maximum Volume Size | Maximum File Size |
---|---|---|
ext4 | 1 EiB | 16 TiB |
XFS | 8 EiB | 8 EiB |
Btrfs | 16 EiB | 16 TiB |
ZFS | 256 EiB | 16 TiB |
exFAT | 128 EiB | 16 TiB |
NTFS | 256 EiB | 16 TiB |
File system fragmentation occurs over time as users create, delete, or modify files, which leads to non-contiguous storage. While ext4 handles fragmentation well under normal use, file systems like XFS may require occasional defragmentation, especially when dealing with large files. Some file systems, like Btrfs, have built-in tools to manage fragmentation more efficiently.
Some file systems, particularly XFS, are optimized for handling large files and may struggle with performance when managing many small files. In environments where frequent access to small files is common, file systems like ext4 or Btrfs may offer better performance.
While file systems like Btrfs and ZFS offer advanced features like snapshots and error detection, others like ext4 lack such mechanisms. In case of data corruption, recovery options may be limited, relying on backups or third-party tools. Additionally, exFAT lacks journaling, increasing the risk of corruption in case of an unexpected shutdown.
Not all Linux file systems support advanced features such as compression, deduplication, or native encryption. For example, ext4 does not natively support these features, while Btrfs and ZFS do. Choosing a file system without these capabilities may require external tools or alternative methods to achieve similar functionality.
Some file systems, like ZFS, face licensing conflicts (CDDL vs. GPL), which limits their integration into certain Linux distributions by default. Users may need to install ZFS manually, and compatibility issues could arise when using ZFS on Linux systems.
Choosing the right Linux file system depends on your specific needs, such as performance, scalability, reliability, and the intended use case. Consider the following points when choosing a file system:
Ultimately, the best file system depends on the type of data, expected workloads, and your specific environment. For general use, ext4 is a reliable default. Consider file systems like XFS, Btrfs, or ZFS for more specialized needs.
Let’s dive in deeper to understand what all the above directories are:
/
The base of the Linux directory (Forward Slash)
The starting point of the FSH
In Linux, everything is treated as files
/bin
Contains executable files that are used to run various system commands & utilities
These executables can be executed by regular users
Example: cp, mv, cat, ls, etc
/boot
Stores files related to the booting process of the Linux system
Example: Boot loader config files, kernel images, etc
/dev
Contains device files
Used to interact with various devices in system such as disks, partitions, printers, and other hardware devices
/etc
Stores configuration files for system wide settings, applications, services, and daemons
Example: /etc/passwd, /etc/hosts, /etc/fstab and etc
/home
Stores home directories of all regular users of the system
Example: /home/<username>
/lib
/media
/mnt
Mnt stands for mount point
Mount point for temporarily mounting file systems, devices, or network shares
/opt
Directory used for installing optional or add-on software packages which are part of the base system
Example: third party softwares
/proc
Proc stands for process
Virtual file system which is used to interact with the kernel to get the system process information, system resources, hardware config and etc in real time
Example: /proc/cpuinfo, /proc/meminfo
/root
/sbin
Stores system executable or binaries
These binaries are reserved to be executed by system admins
/tmp
Tmp stands for temporary
Used to store temporary files that are created and used by various programs and processes by the system
Tmp folder is cleaned after every reboot
/usr
Usr stands for Unix System Resources
Used to store user related files, libraries, etc
Example: /usr/bin, /usr/sbin, /usr/local and etc
/var
Var stands for variables files
Used to store files that are expected to grow/shrink over time
Example: Log files, spool files, temporary files