The Hierarchy
In Linux, everything lives in one big tree that starts at / (the root directory) and
then branches into standard folders with well-defined purposes.
Linux is case-sensitive.
Uppercase and lowercase letters in filenames and directory names are treated as completely distinct.
/boot,
/Boot, and
/BOOT
are three entirely separate directories as far as Linux is concerned.
Top-Level Directories (FHS)
/ (root)
The top of the filesystem hierarchy. Every file and directory is somewhere under /; there are no C: or D: drives.
The directories directly under / contain only what is strictly necessary to boot the system and perform basic recovery tasks β the minimum needed before anything else is loaded. Think of these as the tools a technician would need if the system were damaged and they had to repair it from scratch.
/bin & /sbin
/bin: Essential user binaries (ls, cp).
/sbin: System administration binaries (mount).
/lib: Essential shared libraries for these.
/etc & /boot
/etc: System configuration files (fstab, passwd).
/boot: Files required for booting (kernel, GRUB).
/home & /root
/home: Home directories for normal users.
/root: Home directory of the root user (kept separate).
/usr & /opt
/usr: Installed applications and shared data (/usr/bin).
/opt: Optional or thirdβparty software.
/var, /tmp, /run
/var: Variable data like logs (/var/log).
/tmp: Temporary files.
/run: Runtime state (PIDs, sockets).
/dev & /media
/dev: Device files (/dev/sda, /dev/null).
/media & /mnt: Mount points for removable media.
/proc & /sys
Virtual filesystems exposing kernel and process information.
/proc: Process info (e.g. /proc/cpuinfo).
Interactive Tree
Click any node to expand β and see what lives there
Looking for a specific file?
Use the find command to search the entire file system by name, size, type, and more.
Navigating Paths
Every file and directory can be referenced by a path. Understanding the difference between absolute and relative paths is crucial for command-line navigation.
Absolute Paths
An absolute path is the full path from the root directory all the way to the target. It always starts with a forward slash /.
Tip: Use the pwd command to print your current absolute path. In graphical file browsers, the root directory is often labeled as "Computer".
Relative Paths
A relative path is relative to your current working directory. It never starts with a slash.
..β Moves up one level to the parent directory.~β Shortcut for your home directory../β Used to execute a script in the current directory (e.g.,./script.sh).
Tab Completion: While typing a path, hit the Tab key. Linux will auto-complete the path if it's unique, or list possibilities if you press it twice. This is essential for speed and avoiding typos!
File Naming & Extensions
Naming conventions in Linux are highly flexible but follow best practices to avoid command-line friction.
Naming Rules
- Names can be up to 255 characters long.
- The forward slash
/is reserved and cannot be used. - You cannot name a file exactly
.or...
Extensions
Extensions (like .txt) aren't strictly required by the Linux kernel, but they help GUI applications determine which program should open the file by default.
Best Practices
Keep filenames short and avoid spaces. If a filename has spaces, you must escape them with a backslash (\ ) in the terminal:
Instead of spaces, it is standard convention to use:
- Underscores: Audit_File.txt
- Hyphens: audit-file.txt
- CamelCase: AuditFile.txt
π‘ How to make this "click" in practice
Next time you run a program, mentally trace where things live:
- The binary comes from
/binor/usr/bin. - It loads libraries from
/libor/usr/lib. - It reads system configs from
/etc. - It writes logs to
/var/log. - It uses
/tmpfor temporary data. - The kernel surfaces info via
/procand/sys.
Storage: Physical vs Logical
It is essential to distinguish between the physical storage (the hardware) and logical organisation (the software). This is often described as the difference between the physical "container" and the logical "method" of storage.
1. Partition β The Container
Imagine your hard drive as a physical office building. A partition is a dedicated subsection of that physical media β like a specific floor or suite. It defines a fixed area managed as a single unit. In Linux, partitions appear as device files:
2. Filesystem β The Method
If the partition is the empty office suite, the filesystem is the filing cabinets and indexing system. Without it, a partition is just raw ones and zeros. Formatting a partition installs a filesystem to organise that space:
3. Mounting β The Bridge
Mounting attaches a partition's filesystem to a directory (a mount point) in the tree. There are no drive letters β you "attach" storage to a path:
/dev/sdc1 β /var/log
Note: Generally a filesystem resides within a single partition. However, in some circumstances a filesystem can span more than one partition using symbolic links β a topic covered later in this course.
Windows vs Linux: Storage Concepts
| Concept | Windows | Linux |
|---|---|---|
| Storage access | Drive letters (C:, D:, E:) | Mount points in a single unified tree |
| Physical unit | Volume / Partition | /dev/sda1, /dev/nvme0n1p1 |
| Default filesystem | NTFS | ext4 / XFS / Btrfs |
| Attach storage | Auto-assign drive letter | mount /dev/sdb1 /home |
| Result | New drive letter appears | Directory becomes the partition's root |
Partitions
A partition is a section of the hard disk that logically acts as a separate disk. Partitions enable you to convert a large hard disk into smaller, manageable chunks.
- Must be formatted and assigned a filesystem before storing data.
- Identified using a partition table in the boot record.
- Maximum of four primary partitions per table.
Disk Partitioning
Separates system files from user files. Corrupted partitions do not affect others and can be recovered separately.
- Primary: Contains one filesystem (max 4 per disk). Boot and swap are normally here.
- Extended: Can contain several logical filesystems. Only 1 extended partition allowed.
- Logical: Created within an extended partition. No strict restriction, but limit to 12.
Hard Disk Size Specification
| Partition | Recommended Size |
|---|---|
| / | Minimum 1 GB. |
| /boot | 100 MB. |
| swap | Double the RAM size. |
| /var | Minimum 250 MB. |
| /home | Varies based on the number of users. |
The fdisk Utility
A menu-driven utility program used for creating, modifying, or deleting partitions on a disk drive. Syntax: fdisk [options] {device}
Command Line Options
| Option | Action |
|---|---|
| -b {size} | Specify sector size. |
| -H {heads} | Specify number of disk heads. |
| -S {sectors} | Specify sectors per track. |
| -s {part} | Print partition size in blocks. |
| -v | List fdisk version. |
| -l | List partition tables. |
Interactive Menu Options
| Option | Action |
|---|---|
| n | Create a new partition. |
| d | Remove a partition. |
| p | List existing partitions. |
| w | Write changes to disk and exit. |
| q | Cancel changes and exit. |
$ fdisk --help
Usage:
fdisk [options] <disk> change partition table
fdisk [options] -l [<disk>...] list partition table(s)
Display or manipulate a disk partition table.
Options:
-b, --sector-size <size> physical and logical sector size
-B, --protect-boot don't erase bootbits when creating a new label
-c, --compatibility[=<mode>] mode is 'dos' or 'nondos' (default)
-L, --color[=<when>] colorize output (auto, always or never)
colors are enabled by default
-l, --list display partitions and exit
-x, --list-details like --list but with more details
-n, --noauto-pt don't create default partition table on empty devices
-o, --output <list> output columns
Swap Space & Partitions
Swap space is an area on the hard disk used as virtual memory when the system runs out of physical memory (RAM). Unused files are pushed from RAM to swap to free up space. Usually, swap space is twice the RAM capacity.
Types of Swap
- Device Swap: Configured during partitioning; used to run large applications.
- Filesystem Swap: Configured on install; emergency resource when swap runs out.
- Pseudo-swap: Allows large apps to run on limited RAM computers.
Partitions vs Files
A swap partition is a dedicated area of virtual memory on disk. Linux prefers partitions because they perform better.
A swap file is a dynamic file used to transfer data from RAM to disk when a dedicated partition isn't available or is full.
The mkswap Command
Creates swap space on a disk partition. Syntax: mkswap [options] device {size}
| Option | Enables You To |
|---|---|
| -c | Verify device is free from bad sectors. |
| -f | Force partition larger than limit. |
| -p | Set the page size. |
| -L {label} | Activate swap space using labels. |
Management Commands
| Command | Description |
|---|---|
| swapon -a | Activate all swap space. |
| swapon -e | Skip devices that do not exist. |
| swapoff -a | Deactivate all swap space. |
File Systems
A file system provides a structured method for an OS to store, retrieve, organize, and manage files. It maintains metadata like creation dates, sizes, and permissions.
File System Labels
Labels (up to 16 characters) are assigned for easy identification.
e2label /dev/sda1 mylabel
tune2fs -L mylabel /dev/sda1
Linux File System Types
ext4
Newest default file system for many distros. Supports journaling, volumes up to 1 EiB, and files up to 16 TiB.
XFS
64-bit, high-performance journaling file system for fast recovery and large files. Default for CentOS/RHEL 7.
btrfs
Modern Copy-on-Write (CoW) focusing on fault tolerance, repair, and easy administration.
ext3 / ext2
Legacy native file systems. Ext3 introduced journaling for data integrity over Ext2.
ReiserFS / JFS
Alternative journaling systems. ReiserFS is highly efficient with small files.
swap
Not a true FS, but disk space used as virtual memory when physical RAM runs out.
Access to Other File Systems
FAT / vfat
Compatible with Windows and MS-DOS. Often used for flash drives.
NTFS
Windows default FS with security, encryption, and large drive support.
ISO 9660
Standard for CD/DVDs (CDFS).
The fstab File
Located at /etc/fstab, this config file stores info about storage devices and partitions, dictating where and how they should be automatically mounted on boot.
| Field | Description |
|---|---|
| Device Name | The device or filesystem to mount (e.g. /dev/sda1 or UUID). |
| Mount Point | Where the filesystem is mounted (e.g. /home). |
| FS Type | The filesystem type (e.g. ext4). |
| Mount Options | Comma-separated options (e.g. defaults,ro). |
| Dump Options | 1 if backup utility should back it up, 0 to ignore. |
| fsck Options | Pass order for fsck check (0=disable, 1=root, 2=others). |
The mkfs Command
Builds a Linux filesystem on a device (usually a partition). Syntax: mkfs [fs type] [options] {device}
Common Wrappers
- mkfs.ext4 /dev/sda1
- mkfs.xfs /dev/sda2
- mkfs.btrfs /dev/sdb1
- mkfs.vfat /dev/sdc1
| Option | Description |
|---|---|
| -v / -V | Verbose output. |
| -t {fstype} | Specify FS type. |
| -c | Check for bad blocks before building. |
The mke2fs Command
A specific version of mkfs used strictly to create ext2, ext3, and ext4 filesystems. Syntax: mke2fs [options] {device}
| Option | Description |
|---|---|
| -t {type} | Specify type (ext2, ext3, ext4). |
| -b {size} | Specify block size in bytes. |
| -j | Create a journaled ext3 filesystem. |
| -M | Set directory last accessed to mount. |
Mount Points & The mount Command
A mount point is typically an empty directory on which a filesystem is loaded (mounted) to make it accessible to users. In Linux, a file system cannot be accessed directly; it must be associated with a directory using the mount command, and disassociated using umount.
| Mount Option | Enables You To |
|---|---|
| auto / noauto | Specify if the device should be mounted automatically. |
| user / nouser | Specify if any user (or only root) can mount the device. |
| exec / noexec | Allow/prevent binaries in the filesystem from being executed. |
| ro / rw | Mount filesystem as read-only or read/write. |
| sync / async | Specify if I/O operations should be done synchronously or asynchronously. |
Storage Devices & Mass Storage
Storage devices in Linux are designed for particular use cases, ranging from internal rapid-access disks to portable removable media. Mass storage devices (Hard disks, tape drives, flash drives, CD/DVDs) provide fast access to large amounts of data. These are often controlled by protocols like ATAPI (AT Attachment Packet Interface).
| Device | Description |
|---|---|
| Hard disk | Internal device storing large amounts of data, accessed quickly. |
| Floppy drive | Removable medium for small amounts of data. Slow access. |
| Tape drive | Internal or external magnetic tape storage. Data is accessed sequentially. |
| Flash drive | Small, portable storage device. |
| CD-R(W) | Removable optical disc (650-700 MB). |
| DVD-R(W) | Removable optical disc (4.5 GB or more). |
The lsblk Command
While fdisk is powerful for creating and modifying partitions, it can be a bit heavy to read. For a much cleaner, tree-like view of how your disks, partitions, and mount points connect together, DevOps engineers usually prefer a command called lsblk.
Journaling File Systems
A journaling file system helps an OS quickly recover after a system crash, often removing the need for a file system check at boot. Instead of writing modified files directly to disk, a journal is maintained:
- The journal describes all changes to be made.
- A background process applies each change entered in the journal.
- If the system crashes, pending changes are performed on reboot.
- Incomplete journal entries are simply discarded.
Performance Issues
Journaling works well with small files and small drives. However, performance can suffer as drive size grows due to: filesystem recovery time after a crash, the bitmap tracking method, and wasted space/fragmentation.
Integrity & Repair
Use these commands to check and repair file system integrity after hardware failures or improper shutdowns. Note: Always unmount before checking!
-
fsck - Checks integrity. Syntax:
fsck -t {type} [options]. Similar to DOS chkdsk.
To repair a single filesystem:fsck -r /dev/{fs} -
e2fsck - Specifically checks ext2, ext3, and ext4 filesystems.
Syntax:e2fsck /dev/{fs} -
xfs_repair - Specifically checks and repairs XFS filesystems.
Syntax:xfs_repair [options] /dev/{fs}
The tune2fs Utility
Adjusts tunable parameters on extended filesystems (ext2/ext3/ext4) even after installation. Syntax: tune2fs [options] {device}
| Option | Action |
|---|---|
| -j {part} | Convert to ext3 (adds a journal). |
| -i d|m|w | Max time between checks. |
| -c {count} | Max mounts between checks. |
| -C {count} | Set number of times mounted. |
| -r {count} | Set reserved blocks count. |
| -e {action} | Kernel behavior on error (continue, remount-ro, panic). |
| -l | List superblock contents. |
| -U UUID | Set the UUID. |
Advanced Management Utilities
dumpe2fs
Dumps ext status and prints block group info. Syntax: dumpe2fs [opts] {device}
| -l | Print detailed block report. |
| -b | Print bad blocks. |
| -f | Force display of status. |
| -i | Display from e2image file. |
debugfs
Interactive shell to examine and modify ext filesystems.
| open | Open a file system. |
| close | Close the file system. |
| stats | View file system info. |
| ffb | Find a free block. |
XFS Tools
Manage XFS parameters (always unmount before using xfs_admin).
| xfs_info | Display XFS details. |
| xfs_metadump | Copy metadata to a file. |
| xfs_grow | Expand XFS to fill disk. |
| xfs_db | Debug XFS file system. |