GO KALI FREE
BeginnerLinux

Linux File System Explained: Directory Hierarchy and Structure

A comprehensive guide to the Linux filesystem hierarchy, directory structure, file types, mount points, and navigation commands.

#Linux#filesystem#directory hierarchy#FHS#file management

Understanding the Linux Filesystem

The Linux filesystem is a hierarchical tree structure rooted at /. Unlike Windows which uses separate drive letters (C:, D:, E:), Linux treats every storage device, partition, and network share as a directory within a single unified tree. This design provides consistency across systems and simplifies path management.

The Filesystem Hierarchy Standard (FHS) defines the purpose and contents of directories in Linux systems. Most distributions follow the FHS, so the directory structure is similar across Ubuntu, Kali, Fedora, and others.

Prerequisites

Basic familiarity with the command line including ls,cd, and pwd commands. Understanding file paths (absolute vs relative) is helpful.

The Root Directory

Navigation across the filesystem tree utilizes directory shortcuts including parent directory navigation via cd .., home directory targeting with cd ~, previous working directory switching via cd -, and directory stack navigation with pushd, popd, and dirs.

The root directory / is the top of the filesystem tree. Every file and directory on the system branches from this single point. All paths that start with / are absolute paths because they begin at the root.

Essential Directories Explained

/bin — Essential User Binaries

/bin contains essential command binaries needed for system booting and repair. These commands are available even if other filesystems are not mounted. Common binaries include ls, cp, mv, rm, cat, echo, bash, and sh.

ls /bin | head -10
# Output: bash, cat, chmod, cp, date, echo, grep, kill, less, ln

On modern distributions, /bin is often a symbolic link to /usr/bin.

/boot — Boot Loader Files

/boot contains everything needed to boot Linux: the kernel (vmlinuz), initial RAM disk (initrd.img), boot loader configuration (GRUB), and System.map (kernel symbol table). This directory is often kept small and may be a separate partition.

ls /boot
# vmlinuz-6.1.0-kali9-amd64  initrd.img-6.1.0-kali9-amd64  grub/

/dev — Device Files

Linux treats hardware devices as files. /dev contains device nodes that represent hardware components like hard drives (/dev/sda), partitions (/dev/sda1), terminals (/dev/tty), sound cards (/dev/audio), and random number generators (/dev/urandom).

ls /dev | head -10
# sda, sda1, sda2, tty, null, zero, random, urandom, cdrom, usb

For enumerating attached hardware buses and peripheral controllers, see our guides on PCI hardware with lspci and USB devices with lsusb.

/etc — Configuration Files

/etc (et-cetera) contains system-wide configuration files. This is one of the most important directories for system administration. Examples include:

  • /etc/passwd — User account information
  • /etc/shadow — Encrypted passwords
  • /etc/ssh/sshd_config — SSH server configuration
  • /etc/network/interfaces — Network configuration
  • /etc/apt/sources.list — Package repository list
  • /etc/hosts — Static hostname mapping
  • /etc/fstab — Filesystem mount table
  • cat /etc/os-release
    # PRETTY_NAME="Kali GNU/Linux Rolling"
    # NAME="Kali GNU/Linux"
    

    /home — User Home Directories

    Each regular user gets a subdirectory under /home (except root, whose home is /root). User data, personal configurations (dotfiles), and user-installed programs reside here. The path /home/username is often accessible as ~ for the current user.

    ls -la /home
    # drwxr-xr-x  user1 user1  /home/user1
    # drwxr-xr-x  user2 user2  /home/user2
    

    /lib — System Libraries

    /lib contains shared libraries needed by binaries in /bin and /sbin. These are the equivalent of DLLs on Windows. Library files typically have extensions like .so (shared object) or .a (archive). Kernel modules reside in /lib/modules.

    /media and /mnt — Mount Points

    /media is used for removable media (USB drives, CD-ROMs) that are automatically mounted. /mnt is a generic mount point for temporary manual mounts.

    # Mount a USB drive
    sudo mount /dev/sdb1 /mnt/usb
    ls /mnt/usb
    

    For mounting filesystems into the directory hierarchy and safely unmounting storage volumes, consult our references on mount and umount.

    /opt — Optional Software

    /opt is reserved for third-party software packages that are not part of the distribution's package manager. Software here is self-contained in its own subdirectory. Examples include Google Earth, Oracle Database, and some commercial tools.

    /proc — Process Information

    Kernel state and hardware interaction can be directly queried via lsmod to enumerate active kernel modules and modinfo to inspect module metadata and driver firmware parameters.

    /proc is a virtual filesystem that provides runtime system information. It contains files for every running process (numbered directories), system information (/proc/cpuinfo, /proc/meminfo), and kernel parameters (/proc/sys). Files in /proc are dynamically generated and do not occupy disk space.

    cat /proc/cpuinfo | head -5
    cat /proc/meminfo | head -5
    ls /proc | grep -E '^[0-9]+$' | head -10  # Process IDs
    

    To inspect hardware diagnostic logs directly from the kernel ring buffer, explore our dmesg command reference, and for real-time virtual memory, paging, and CPU statistics, see vmstat. To rapidly find files across the indexed filesystem hierarchy without live disk traversal, consult our locate command guide. For high-performance archive compression and decompression, review our references for bzip2, bunzip2, xz, unxz, and multi-format archiving with 7z.

    /root — Root Home Directory

    The home directory for the root (administrator) user is /root, not /home/root. This separation ensures root can log in even if /home is unmounted during recovery.

    /sbin — System Binaries

    /sbin contains system administration binaries used for system maintenance. These commands typically require root privileges. Examples include partition table inspection and creation with fdisk and modern GPT partitioning with parted, block device UUID and attribute discovery with blkid, filesystem creation with mkfs, filesystem consistency checking with fsck, low-level block copying with dd, and interactive visual disk space analysis with ncdu.

    /tmp — Temporary Files

    /tmp is world-writable and stores temporary files. Files in /tmp are typically deleted on system boot. The sticky bit (t) on /tmp prevents users from deleting each other's files.

    ls -la / | grep tmp
    # drwxrwxrwt  ... /tmp
    

    /usr — User System Resources

    /usr is the largest directory on a typical Linux system. It contains user utilities, applications, libraries, documentation, and source code.

    /var — Variable Data

    /var stores data that changes frequently during system operation: logs (/var/log), spools (/var/spool), temporary files preserved between reboots (/var/tmp), cache data (/var/cache), web server root (/var/www), and database state (/var/lib).

    du -sh /var/log
    ls /var/log/
    

    File Types in Linux

    Linux treats everything as a file. The first character of ls -l output indicates the file type:

    CharacterFile TypeExample
    -Regular file-rw-r--r--
    dDirectorydrwxr-xr-x
    lSymbolic linklrwxrwxrwx
    cCharacter devicecrw-rw-rw-
    bBlock devicebrw-rw----

    Mount Points and Partitions

    mount | head -10
    

    Real-World Examples

    Finding Large Log Files: du -sh /var/log/* | sort -rh | head -10

    Checking Disk Usage by Directory: du -sh /* 2>/dev/null | sort -rh | head -10

    Finding Configuration Files: find /etc -name "*.conf" -type f

    Common Mistakes

    Confusing /bin and /usr/bin — on modern systems they are often symlinked. Never delete files in /proc or /sys. Ignoring /etc when troubleshooting.

    Best Practices

    Use df -h to monitor disk space. Use du -sh for directory sizes. Keep /boot clean of old kernels. Understand symbolic links — they are pointers, not copies.

    Related Tools

    ncdu — Interactive disk usage analyzer. du — Estimate directory space. df — Filesystem disk space. lsblk — List block devices. find — Search for files. tree — Display directory structure.

    Related Articles

  • linux-commands-explained
  • linux-file-permissions
  • command-line-essentials
  • linux-terminal-guide
  • kali-linux-beginner-guide
  • Summary

    The Linux filesystem follows the FHS with a single root directory /. Key directories include /bin (commands), /etc (configuration), /home (user data), /var (logs), /tmp (temporary files), and /usr (applications). Understanding this structure is fundamental to Linux administration and security.

    Knowledge Check

  • What is the root directory symbol in Linux?
  • Which directory contains system configuration files?
  • What is special about the /proc directory?
  • Where are user home directories stored?
  • What command shows mounted filesystems?
  • Frequently Asked Questions

    What is the Linux filesystem hierarchy standard (FHS)?

    The FHS defines the purpose and contents of directories in Linux systems, ensuring consistency across distributions. It specifies that /etc holds configuration files, /var stores logs, /home contains user data, and /bin holds essential commands. See our Linux commands guide for navigation basics.

    What is the difference between /bin and /usr/bin?

    On modern Linux distributions, /bin is often a symbolic link to /usr/bin — they contain the same essential command binaries. Historically, /bin held commands needed during boot while /usr/bin held user commands after /usr was mounted. The distinction is largely cosmetic today.

    Why is /proc important for system administration?

    /proc is a virtual filesystem that provides real-time system information including per-process details (by PID number), CPU and memory info via /proc/cpuinfo and /proc/meminfo, and kernel parameters under /proc/sys. Files here are generated dynamically and use no disk space.

    Where should I store user files in Linux?

    User files belong in /home/username, which contains personal configurations (dotfiles), documents, and user-installed programs. The tilde (~) shorthand expands to the current user's home directory. Root's home is /root, not /home/root, ensuring root access even if /home is unmounted.

    What is the /tmp directory used for?

    /tmp stores temporary files that are typically deleted on reboot. It is world-writable but protected by the sticky bit, which prevents users from deleting each other's files. Never store important data in /tmp — use /var/tmp for files that need to survive reboots.

    What is the difference between /var and /tmp?

    /var stores variable data that persists between reboots (logs, caches, databases), while /tmp holds temporary files deleted on boot. /var/log contains system logs, /var/cache holds package manager caches, and /var/tmp preserves temporary files across reboots unlike /tmp.

    How do I find which directory uses the most disk space?

    Use du -sh /* 2>/dev/null | sort -rh | head -10 to list the largest top-level directories. For interactive exploration, install ncdu with sudo apt install ncdu and run it on any path. This is essential for managing disk usage on servers.

    What are device files in /dev?

    Linux represents hardware as files in /dev: hard drives (/dev/sda), partitions (/dev/sda1), terminals (/dev/tty), and null/random devices (/dev/null, /dev/urandom). The null device discards input (like /dev/null), while urandom generates random numbers used by security tools and encryption.

    Where are system configuration files stored?

    System-wide configuration lives in /etc, including /etc/passwd (user accounts), /etc/ssh/sshd_config (SSH server), /etc/hosts (static DNS), and /etc/fstab (mount table). User-specific configs are dotfiles in the home directory like ~/.bashrc. Learn more in our Linux terminal guide.

    What is the difference between absolute and relative paths?

    Absolute paths start from the root directory (/) like /etc/hosts and always resolve to the same location. Relative paths start from the current directory like ../config/file and change depending on where you are. Use pwd to print your current directory and understand your relative position.

    Continue Learning

    Linux · Beginner

    Command Line Essentials: Mastering the Terminal for Security Work

    Essential command line skills for cybersecurity professionals including navigation, text processing, scripting, and automation.

    Linux · Beginner

    Linux Package Management: APT, DPKG, and Beyond

    Master Linux package management across Debian-based systems including APT, DPKG, repository configuration, dependency resolution, and troubleshooting.

    Linux · Beginner

    Linux Process Management: Monitoring and Controlling Processes

    Learn to manage Linux processes effectively including monitoring tools, signals, priority control, background jobs, and automation with systemd.

    Linux · Beginner

    What is Linux? Understanding the Open Source Operating System

    A beginner-friendly introduction to Linux covering its history, architecture, distributions, kernel, and why it is essential for cybersecurity professionals.

    Related Security Tools

    Information Gathering

    SMBClient

    Learn how to use SMBClient on Kali Linux: install Samba's FTP-like SMB/CIFS client, list shares, connect as a guest or with credentials, browse folders, and upload or download files on Windows, Samba, or NAS devices. For authorized assessments, check ports 139/445 with Nmap before testing share permissions.

    Information Gathering

    Enum4linux

    Learn how to use Enum4linux to enumerate Windows and Samba systems over SMB: install it on Kali Linux, run your first scan, read the users, shares, groups and password policy it returns, and switch to enum4linux-ng for modern hosts that block null sessions.

    Password Attacks

    Hydra

    Hydra is a parallelized login cracker that supports numerous protocols including FTP, HTTP, HTTPS, SMB, SSH, and many more. It performs rapid dictionary attacks against login pages and services to test password strength.

    Post Exploitation

    Evil-WinRM

    Learn how to use Evil-WinRM, a Ruby-based client for the Windows Remote Management (WinRM) protocol. This guide covers installation, your first connection, password, pass-the-hash and Kerberos authentication, file transfers and script execution, all for use in authorized lab environments.

    Practice Linux Skills

    Command reference

    Linux Commands Reference

    Browse 163 practical Linux and Kali terminal commands.

    Interactive practice

    Terminal Sandbox

    Practice common Linux commands safely in your browser.

    Written by GO KALI FREE Team