Linux Directory Structure: Explained for Beginners 

linux directory structure

Table of Contents

Get up to 50% off now

Become a partner with CyberPanel and gain access to an incredible offer of up to 50% off on CyberPanel add-ons. Plus, as a partner, you’ll also benefit from comprehensive marketing support and a whole lot more. Join us on this journey today!

If you are acquainted with the Linux ecosystem, you must be familiar with the terms like root, lib, bin, and more. All these are directories that you find in all Linux distributions. 

In fact, the Linux file hierarchy system is a tribute that defines the directory structure and the purpose of them. However, it can get pretty confusing pretty fast, which is why this guide will walk through the Linux directory structure in detail with all the directories and their purpose! 

Understanding the Root Directory (/) in Linux

The root directory is the top level directory in the Linux file system, which acts as a foundation for all the other files and directories. Every directory and file in Linux is organized in a hierarchy under the / sign, making it the start point for the system structure. 

Key Aspects of the Root Directory (/)

  1. Top-Level Directory
    • The / directory contains all system files, configurations, and user files.
    • Unlike Windows, which has multiple drives (C:, D:, etc.), Linux has a single-rooted file system.
  2. Critical for System Operation
    • Essential system files, including the kernel, boot files, and configuration settings, reside under /.
    • Incorrect modifications can lead to system failures.
  3. Root vs. Root User
    • / refers to the root directory (top-level system directory).
    • /root is the home directory for the root (administrator) user.

Here is a table with quick descriptions of all the root directories in the file structure. 

DirectoryDescription
/The root directory; the top-level directory that contains all other directories and files.
/binStores essential binary executables (e.g., ls, cp, mv), available to all users.
/sbinContains system administration binaries (e.g., fsck, iptables), usually restricted to root users.
/etcStores configuration files for system-wide settings and services.
/homeContains user home directories, where personal files and settings are stored.
/rootThe home directory of the root user (administrator).
/usrHolds user utilities, libraries, and applications (e.g., /usr/bin, /usr/lib).
/varStores variable data like logs (/var/log), mail (/var/mail), and temporary files.
/tmpA temporary storage directory for system and user files; cleared on reboot.
/devContains device files for hardware like disks (/dev/sda), USBs, and terminals.
/procA virtual file system providing system information (processes, memory, CPU details).
/sysSimilar to /proc, used for interacting with the kernel and hardware devices.
/mntA generic mount point for attaching external storage (e.g., USBs, network drives).
/mediaAutomatically mounts removable media like USB drives and CDs.
/optUsed for optional third-party software installations.
/srvStores data for services like web servers (/srv/www), FTP, or databases.
/libContains essential shared libraries required by /bin and /sbin binaries.
/lib64Stores 64-bit libraries on 64-bit systems.
/bootHolds bootloader files and the Linux kernel (vmlinuz), necessary for booting.
/runStores runtime data like process IDs (/run/lock, /run/shm); replaces older /var/run.

Key Linux Directories and Their Functions

The Linux file system follows a pre-set hierarchy, which shows that each root directory serves a well-thought out function. Here is a breakdown of Linux directory structure with the most important directories and their purposes. 

  1. /bin – Essential User Binaries

This directory contains essential command-line utilities used by all the users, including non-root users. Examples: ls, cp, mv, cat, echo, grep.

Tech Delivered to Your Inbox!

Get exclusive access to all things tech-savvy, and be the first to receive 

the latest updates directly in your inbox.

  1. /sbin – System Binaries

In the Linux directory structure, /sbin stores the system administration commands, typically used by the root user. Examples: fsck, iptables, reboot, shutdown, mount.

  1. /etc – Configuration Files

The /etc configuration files hold system-wide configuration files and startup scripts. Examples: /etc/passwd (user accounts), /etc/fstab (disk mount settings).

  1. /home – User Home Directories

The /home is a personal directory for each individual user to store files, settings, and configurations. Example: /home/alex/Documents/ for user “alex”.

  1. /var – Variable Data (Logs, Caches, etc.)

The /var is a variable data directory that stores all the frequently changing data variables like logs, mails, caches, and temp files. Examples: /var/log/syslog, /var/cache/apt, /var/www (web server files).

  1. /usr – User Programs and Utilities

In the Linux directory structure, /usr contains user-related programs and libraries and is usually installed by the system package manager. Examples: /usr/bin/ (user applications), /usr/lib/ (libraries).

  1. /opt – Optional Software Packages

The /opt directory stores third-party applications and softwares that are installed manually. Examples: /opt/google/chrome/ for Google Chrome installation.

  1. /tmp – Temporary Files

In the Linux directory structure, the /tmp file is used to store temporary files, automatically cleared on reboot. Example: /tmp/session123.tmp.

  1. /dev – Device Files

The /dev, also known as the device files contains special device files that represent hardware components. Examples: /dev/sda (hard drive), /dev/tty (terminal), /dev/null.

  1. /mnt and /media – Mount Points

In the Linux directory structure;

  • /mnt: Temporary mount location for external drives or network shares.
  • /media: Automatically mounts removable media like USBs and CDs.
  1. /proc and /sys – Kernel and System Information

In the Linux directory structure;

Enhance Your CyerPanel Experience Today!
Discover a world of enhanced features and show your support for our ongoing development with CyberPanel add-ons. Elevate your experience today!

  • /proc: A virtual file system containing system information, including process details. Example: /proc/cpuinfo (CPU details).
  • /sys: Exposes hardware and kernel-related parameters. Example: /sys/class/net/ (network interfaces).
Linux Directory Structure: Explained for Beginners 

How to Navigate the Linux File System

It is important to understand how to navigate the Linux directory structure to efficiently manage files, directories, and the system resources. Here is how you can move through the system efficiently:

  1. Understanding the Linux Directory Structure

Use the ls command to list files and directories in a given location.

ls /

  1. Moving Between Directories

Use the change directory (cd) command to move between the directories. For example if you need to move to the home directory: 

Examples:

  • Move to the home directory:
    cd ~
  • Navigate to the root directory (/):
    cd /
  • Move to the etc directory:
    cd /etc
  • Go back one directory up:
    cd ..
  • Return to the previous directory:
    cd –
  1. Viewing Directory Contents
  • List all files and directories:
    ls
  • List files with detailed information (permissions, size, owner, etc.):
    ls -l
  • Show hidden files (files starting with .):
    ls -a
  1. Finding Your Current Location

Use the pwd (Print Working Directory) command to see your current directory path:
pwd

  1. Searching for Files and Directories
  • Find a file by name:
    find / -name filename
  • Search for a specific file type (e.g., .txt files in /home):
    find /home -type f -name “*.txt”
  • Locate a command or file using which or whereis:
    which python

whereis nano

  1. Viewing File and Directory Details
  • Display details of a specific file:
    stat filename
  • Show disk usage of a file or directory:
    du -sh /var/log
  • Check available disk space:
    df -h
  1. Navigating with Tab Completion

Use the Tab key for auto-completing filenames or commands. Example: Type cd /us and press Tab, it will autocomplete to /usr if available.

  1. Understanding Absolute vs. Relative Paths
  • Absolute Path: Full path from / (root).
    cd /home/user/Documents
  • Relative Path: Path from the current directory.
    cd Documents

Practical Commands for Managing Directories

CommandDescriptionExample
pwdDisplays the current working directory.pwd
lsLists files and directories in the current directory.ls /home
ls -lLists files with detailed information (permissions, owner, size, etc.).ls -l /var/log
ls -aLists all files, including hidden ones (starting with .).ls -a /etc
cd directoryChanges the current directory.cd /home/user/Documents
cd ..Moves up one directory level.cd ..
cd –Switches to the previous directory.cd –
mkdir directoryCreates a new directory.mkdir new_folder
mkdir -p parent/childCreates nested directories (if parent doesn’t exist).mkdir -p project/src
rmdir directoryRemoves an empty directory.rmdir old_folder
rm -r directoryDeletes a non-empty directory and its contents.rm -r my_folder
mv old newRenames or moves a directory.mv old_folder new_folder
cp -r source destinationCopies a directory and its contents.cp -r /etc /backup
find /path -type d -name nameFinds a directory by name.find /home -type d -name “Documents”
du -sh directoryShows the total size of a directory.du -sh /var/log

Conclusion: Why Understanding Linux Directories Matters

Understanding Linux directories is essential for efficient system navigation, security, and troubleshooting. Each directory has a specific role, from storing system files to managing user data. Knowing their structure improves workflow, access control, and system performance. Mastering directories helps in better file management and problem-solving.

Frequently Asked Questions

1. Can I delete files from /tmp?

Yes, files in /tmp are temporary and usually get deleted automatically on system reboot. However, manually removing unnecessary files can free up space.

2. What is the difference between /mnt and /media?

Both /mnt and /media are used for mounting external storage devices. /mnt is traditionally used for manual mounts, while /media is commonly used for automatic mounting of removable devices.

3. What is the Linux directory structure?

The Linux directory structure is a hierarchical system where all files and directories originate from the root directory (/). It organizes files systematically for better management and functionality.

Marium Fahim
Hi! I am Marium, and I am a full-time content marketer fueled by an iced coffee. I mainly write about tech, and I absolutely love doing opinion-based pieces. Hit me up at [email protected].
Unlock Benefits

Become a Community Member

SIMPLIFY SETUP, MAXIMIZE EFFICIENCY!
Setting up CyberPanel is a breeze. We’ll handle the installation so you can concentrate on your website. Start now for a secure, stable, and blazing-fast performance!