Skip to content

File System Structure

Overview

Linux adopts a hierarchical tree-like file system structure where all files and directories start from the root directory (/). Unlike Windows which uses multiple drive letters (C:, D:), Linux mounts all storage devices to this single directory tree.

Filesystem Hierarchy Standard (FHS)

Linux follows the Filesystem Hierarchy Standard (FHS), which defines specifications for directory structure and content.

Directory Tree Overview

/
├── bin       → Basic command binary files
├── boot      → Boot loader files
├── dev       → Device files
├── etc       → System configuration files
├── home      → User home directories
├── lib       → Shared library files
├── media     → Removable media mount points
├── mnt       → Temporary mount points
├── opt       → Third-party applications
├── proc      → Process and kernel information (virtual)
├── root      → Root user's home directory
├── run       → Runtime data
├── sbin      → System administration commands
├── srv       → Service data
├── sys       → Kernel and device information (virtual)
├── tmp       → Temporary files
├── usr       → User programs and data
└── var       → Variable data files

Important Directories Explained

/ (Root Directory)

The root directory is the starting point of the file system; all directories and files are its descendants.

bash
$ ls /
bin   dev  home  lib64  mnt  proc  run   srv  tmp  var
boot  etc  lib   media  opt  root  sbin  sys  usr

/bin and /sbin

Store binary files for basic commands.

bash
# /bin - Basic commands available to all users
$ ls /bin
bash  cat  cp  ls  mkdir  mv  rm  ...

# /sbin - System administration commands (usually require root permissions)
$ ls /sbin
fdisk  fsck  ifconfig  init  ip  reboot  shutdown  ...

Note: In modern Linux distributions, /bin and /sbin are usually symbolic links to /usr/bin and /usr/sbin.

/boot

Contains files needed to boot Linux.

bash
$ ls /boot
config-5.15.0-generic        # Kernel configuration
initrd.img-5.15.0-generic    # Initial ramdisk
vmlinuz-5.15.0-generic       # Compressed Linux kernel
grub/                        # GRUB boot loader

/dev

Device file directory. Linux represents hardware devices as files.

bash
$ ls /dev
sda       # First hard disk
sda1      # First partition of first hard disk
sdb       # Second hard disk
nvme0n1   # NVMe SSD
tty       # Terminal device
null      # Null device (discards all input)
zero      # Zero device (generates null bytes)
random    # Random number generator

Common Device Files

DeviceDescription
/dev/nullDiscards all written data
/dev/zeroProvides infinite null bytes
/dev/randomGenerates random data
/dev/sdaFirst SATA/SCSI hard disk
/dev/nvme0n1First NVMe hard disk
/dev/ttyCurrent terminal

/etc

System configuration files directory (Editable Text Configuration).

bash
$ ls /etc
apt/           # APT package manager configuration
bash.bashrc    # System-level Bash configuration
crontab        # Scheduled tasks
fstab          # Filesystem mount table
group          # Group information
hostname       # Hostname
hosts          # Hostname resolution
network/       # Network configuration
passwd         # User account information
shadow         # Encrypted user passwords
ssh/           # SSH configuration
sudoers        # sudo configuration

Important Configuration Files

FileDescription
/etc/passwdUser account information
/etc/shadowEncrypted passwords
/etc/groupUser group information
/etc/fstabDisk mount configuration
/etc/hostsLocal DNS resolution
/etc/hostnameHostname
/etc/resolv.confDNS server configuration
/etc/crontabSystem scheduled tasks

/home

Home directory for regular users.

bash
/home
├── maxwell/
   ├── Desktop/
   ├── Documents/
   ├── Downloads/
   ├── .bashrc        # User Bash configuration
   ├── .profile       # Login configuration
   └── .ssh/          # SSH keys
├── alice/
└── bob/

Each user has their own directory under /home for storing personal files and configuration.

bash
# Home directory can be represented by ~
$ cd ~
$ cd ~/Documents

/lib and /lib64

Shared library files (similar to Windows DLL).

bash
$ ls /lib
modules/           # Kernel modules
x86_64-linux-gnu/  # 64-bit library files

/media and /mnt

Mount point directories.

  • /media: Automatically mounted removable devices (USB, CD)
  • /mnt: Temporary manual mount points
bash
# View mounted devices
$ ls /media/$USER/
USB_DRIVE/  CD_ROM/

# Manual mount
$ sudo mount /dev/sdb1 /mnt

/opt

Third-party application installation directory.

bash
/opt
├── google/
   └── chrome/
├── visual-studio-code/
└── lampp/

/proc

Virtual filesystem providing process and kernel information.

bash
$ ls /proc
1/              # Process info with PID 1
self/           # Current process
cpuinfo         # CPU information
meminfo         # Memory information
version         # Kernel version

Common Files

bash
# View CPU information
$ cat /proc/cpuinfo

# View memory information
$ cat /proc/meminfo

# View kernel version
$ cat /proc/version

# View system uptime
$ cat /proc/uptime

# View specific process information
$ ls /proc/1234/
cmdline  cwd  environ  exe  fd  maps  status  ...

/root

Home directory for root user (superuser).

bash
# Note: Not /home/root
$ sudo ls /root

/run

Runtime data directory, storing temporary data since system boot.

bash
$ ls /run
lock/       # Lock files
user/       # User runtime data
systemd/    # systemd data

/srv

Service data directory, storing data provided by system services.

bash
/srv
├── ftp/       # FTP service data
├── http/      # Web service data
└── git/       # Git repositories

/sys

Virtual filesystem providing kernel, device, and driver information.

bash
$ ls /sys
block/    # Block devices
bus/      # Bus
class/    # Device classes
devices/  # Devices
power/    # Power management

/tmp

Temporary files directory. Contents may be cleared after system reboot.

bash
$ ls /tmp
systemd-private-xxx/
  • All users can write to it
  • Usually configured for periodic cleanup
  • Suitable for storing temporary data

/usr

User programs and data (Unix System Resources).

bash
/usr
├── bin/        # User commands
├── include/    # C header files
├── lib/        # Library files
├── local/      # Locally installed software
   ├── bin/
   ├── lib/
   └── share/
├── sbin/       # System administration commands
├── share/      # Architecture-independent data
   ├── doc/    # Documentation
   ├── man/    # Manual pages
   └── icons/  # Icons
└── src/        # Source code

Subdirectory Description

DirectoryDescription
/usr/binUser commands
/usr/sbinSystem administration commands
/usr/libLibrary files
/usr/localLocally installed software
/usr/shareShared data (docs, icons, etc.)
/usr/includeC/C++ header files

/var

Variable data files (Variable).

bash
/var
├── cache/      # Application cache
├── lib/        # Program state data
├── log/        # Log files
├── mail/       # Mail
├── run/        # Runtime data (link to /run)
├── spool/      # Queue data
└── tmp/        # Persistent temporary files

Important Subdirectories

bash
# Log files
$ ls /var/log/
syslog        # System log
auth.log      # Authentication log
kern.log      # Kernel log
apt/          # APT log
nginx/        # Nginx log

# Package manager cache
$ ls /var/cache/apt/
archives/     # Downloaded deb packages

File Types

In Linux, everything is a file. File types include:

SymbolTypeDescription
-Regular fileText, binary, images, etc.
dDirectoryContainer for other files
lSymbolic linkPoints to another file
bBlock deviceHard drive, USB, etc.
cCharacter deviceTerminal, keyboard, etc.
sSocketInter-process communication
pPipeFIFO, inter-process communication

Viewing File Types

bash
# Using ls -l, look at first character
$ ls -l
drwxr-xr-x 2 user user 4096 Jan 1 10:00 Documents    # Directory
-rw-r--r-- 1 user user  123 Jan 1 10:00 file.txt     # Regular file
lrwxrwxrwx 1 user user    7 Jan 1 10:00 link -> file # Symbolic link

# Using file command
$ file /bin/ls
/bin/ls: ELF 64-bit LSB pie executable...

$ file /etc/passwd
/etc/passwd: ASCII text

$ file /dev/sda
/dev/sda: block special

Mounting Filesystems

Understanding Mounting

Linux mounts different storage devices to specific locations in the directory tree.

bash
# View mounted filesystems
$ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1        50G   15G   32G  32% /
/dev/sda2       200G   80G  110G  43% /home
/dev/sdb1       500G  100G  400G  20% /data

# Detailed mount information
$ mount
/dev/sda1 on / type ext4 (rw,relatime)
/dev/sda2 on /home type ext4 (rw,relatime)

/etc/fstab

Defines filesystems that are automatically mounted at system startup.

bash
$ cat /etc/fstab
# <device>          <mount point>  <type>  <options>        <dump> <pass>
/dev/sda1         /         ext4    defaults      0      1
/dev/sda2         /home     ext4    defaults      0      2
/dev/sdb1         /data     ext4    defaults      0      2
UUID=xxx          /boot     ext4    defaults      0      2

Manual Mounting

bash
# Mount USB drive
$ sudo mount /dev/sdb1 /mnt/usb

# Mount ISO file
$ sudo mount -o loop ubuntu.iso /mnt/iso

# Mount network share
$ sudo mount -t nfs server:/share /mnt/nfs

# Unmount
$ sudo umount /mnt/usb

Common Filesystem Types

TypeDescription
ext4Default Linux filesystem, stable and reliable
xfsHigh performance, suitable for large files
btrfsSupports advanced features like snapshots, compression
ntfsWindows filesystem
fat32/vfatGood compatibility, common for USB drives
exfatLarge file support, cross-platform
nfsNetwork filesystem
tmpfsMemory-based filesystem

Hidden Files

Files or directories starting with a dot (.) are hidden.

bash
# View hidden files
$ ls -a
.  ..  .bashrc  .profile  .config  Documents

# Common hidden files
~/.bashrc        # Bash configuration
~/.profile       # Login configuration
~/.bash_history  # Command history
~/.ssh/          # SSH configuration and keys
~/.config/       # Application configuration
~/.local/        # User local data

Finding File Locations

which - Find Command Location

bash
$ which ls
/usr/bin/ls

$ which python
/usr/bin/python

whereis - Find Command, Source, and Manual

bash
$ whereis ls
ls: /usr/bin/ls /usr/share/man/man1/ls.1.gz

type - Command Type

bash
$ type ls
ls is aliased to `ls --color=auto'

$ type cd
cd is a shell builtin

$ type /usr/bin/ls
/usr/bin/ls is /usr/bin/ls

Summary

Understanding Linux filesystem structure is the foundation of using Linux:

  • Root directory / is the starting point of the entire filesystem
  • /home stores user personal files
  • /etc stores system configuration
  • /var stores variable data (logs, etc.)
  • /usr stores user programs
  • /tmp stores temporary files
  • /dev/proc/sys are special virtual filesystems

Being familiar with the purpose of these directories will help you better manage and maintain your Linux system.


Previous chapter: Terminal Basics

Next chapter: File Operations

Content is for learning and research only.