Demystifying the Linux Directory Structure: A Roadmap for Your Files

Demystifying the Linux Directory Structure: A Roadmap for Your Files

This article provides an overview of the Linux File System directory structure, highlighting key files, their functions, and where they are located.

The Linux directory structure is similar to a well-organized filing cabinet. It helps keep your system running smoothly by specifying where files and folders are located, making them simple to find and handle.

Categories of files in Linux

There are three broad categories of files in Linux.

  • General Files - These are regular files like documents, images, audio, and video files, containing binary or ASCII data.

  • Directory Files - In Linux, directories are considered files because they store other files and folders.

  • Device Files -These are special files that act as a link to device drivers. They help hardware devices like mice, keyboards, USB devices, and hard drives work on the system. You can find them in the /dev directory.

Linux Directory Structure Diagram

The Root of It All: Forward Slash (/)

Imagine a single tree trunk – that's the forward slash (/). It represents the root directory, the foundation from which all other directories and files branch out. Every path to a file or folder starts here.

Root directory in linux ( this is amazon linux running on ec2 instance)

Essential Branches: Core Directories

Think of the main branches of the tree as these crucial directories:

/bin (binaries) :

The /bin directory contains user binaries, executable programs, and common system commands that are used by all users in the system. These are the tools you use to perform basic system tasks like: cp (copy), mv (move), rm (remove), ls (list), cat (display contents),adduser (add user), passwd (change password), shutdown (shut down), reboot (restart)

These commands are readily available and executable by most users without needing root privileges (administrator access).


/sbin :

Similar to /bin, the /sbin directory contains executable programs meant for system administration tasks. These programs usually require root privileges to run because they can affect the stability of the system. Some examples : fdisk (manage disk partitions),mount (mount a filesystem)


/etc :

This directory contains system configuration files for all the services, scripts, and third-party applications that are installed. Modifying these files can significantly impact system behavior, so caution and understanding are advised.

Some key subdirectories within /etc include:

  • /etc/passwd: Stores user account information.

  • /etc/shadow: Holds encrypted password information (for security reasons, not directly readable).

  • /etc/fstab: Defines how storage devices are mounted.

  • /etc/network: Contains network configuration files.


/var (variable) :

This directory contains variable data that changes over time. Unlike /etc's configuration files, which are relatively static, the contents of /var are constantly growing or being modified.

Examples include:

  • /var/log: Stores system logs, useful for troubleshooting and system monitoring.

  • /var/lib: Holds application-specific data.

  • /var/tmp: Temporary storage for files created by applications, often cleared during system restarts.


/lib (libraries):

This directory contains system libraries, which are reusable blocks of code that programs rely on to function. Imagine a toolbox – libraries provide the essential tools that many programs need to perform their tasks. Modifying libraries directly is not recommended for most users, as it can affect multiple applications.


/usr (user):

Often referred to as the "user space," this directory holds user programs, applications, and libraries. It's a vast directory with numerous subdirectories depending on your specific Linux distribution.

Some common subdirectories include:

  • /usr/bin: Similar to /bin, but may contain additional user-oriented commands.

  • /usr/sbin: Similar to /sbin, but may contain additional user-oriented system administration tools.

  • /usr/share: Contains shared resources like icons, fonts, and documentation.

  • /usr/local: Intended for locally installed software, not distributed with the main Linux system.


/home (home) :

This directory is your personal space! It contains a subdirectory for each user account on the system that contains a user’s personal folders and files. On a graphical Linux system, the home directory, by default, contains folders such as Desktop, Documents, Downloads, Pictures, Videos, and Public.


Additional Branches

Beyond the essential core directories, the Linux directory structure encompasses a variety of additional branches that cater to specific functionalities and system needs. Here's a glimpse into some of these noteworthy directories:

/root :

The /root directory is the home directory for the root user, which is also referred to as the root user’s home directory (and not as the root (/) directory).

The root account also referred to as the superuser, administrative user, system administrator or just the root user has all the access to commands and system files in Linux.

/boot (Bootloader) :

This directory contain files crucial for the boot process, the sequence of events that gets your system up and running. It typically contains:

  • The kernel image, the core of the operating system.

  • Files such as ‘vmlinuz‘ represent the compressed image of the Linux kernel.

  • Configuration files for the bootloader, like GRUB (GRand Unified Bootloader).

  • Initial RAM disk image (initrd), containing essential drivers and file systems needed during boot.


/dev (Device Files) :

This directory contains special files that represent physical hardware devices like hard drives, network interfaces, and CD-ROM drives. Programs interact with these device files to access the hardware. For example, the file /dev/sda might represent your primary hard drive.


/mnt (Mount Point) :

This directory is traditionally used as a temporary mount point for external storage devices like USB drives or additional partitions. You'll typically mount these devices on specific subdirectories within /mnt. For example, you might mount a USB drive on /mnt/usb.


/opt (optional) :

This directory is intended for storing add-on software packages that are not part of the core system distribution. Software installed through package managers might not necessarily use /opt, but it's a common convention for third-party applications. For example, when you install applications such as Skype, Discord, Spotify, and Java, to mention a few, they get stored in the /opt directory.


/proc (Process Information) :

This is a virtual directory that provides information about running processes on the system. It doesn't contain actual files, but rather exposes process details through a filesystem-like interface. For example, the file /proc/cpuinfo contains information about the system's CPU. The filesystem is made when the system starts up and disappears when the system is turned off.


/sys (System) :

Similar to /proc, this directory provides a virtual interface to access system kernel information. It offers details about devices, memory, and other system parameters.


/media :

The /media directory is a directory where the system mounts removable media such as USB drives.


/temp (Temporary) :

This directory serves as a storage space for temporary files created by applications. These files are usually temporary and meant to be removed after they are used, typically cleared during system restarts.


/run (Run Time) :

This directory holds files and data used by system processes while they are running. It might contain information about systemd services or session logs. The contents of /run are typically cleared during system restarts.


/srv :

The /srv directory is the service directory and is abbreviated as ‘srv‘. This directory contains server-specific and service-related files.


/lost+found :

The /lost+found directory is installed during the installation of Linux, useful for recovering files that may be broken due to unexpected shut-down.


/selinux (Security Enhanced Linux) (if applicable) :

On systems with Security Enhanced Linux (SELinux) enabled, this directory contains configuration files and policy modules that define the security framework. SELinux enforces access controls on the system, aiming to enhance security.