LPIC-1 Module 4: Devices, Linux Filesystems, and Filesystem Hierarchy Standard (FHS)

Published On: 20 July 2025

Objective

In any Linux system, understanding how storage devices are managed, how filesystems operate, and how files are structured is essential for every administrator or power user. Whether you're preparing for a certification like LPIC-1 or RHCSA, or aiming to deepen your practical knowledge, mastering devices, filesystems, and the Filesystem Hierarchy Standard (FHS) will significantly boost your system administration skills.

Topic 104.1: Create Partitions and Filesystems

What is Creating Partitions and Filesystems?

Before a disk can be used in Linux, it must be divided into logical sections called partitions. These partitions define the areas on the disk where files and data will reside. After partitioning, each partition must be formatted with a filesystem a structure that defines how data is stored and accessed. Common Linux filesystems include ext4, XFS, and VFAT, among others. This two-step process ensures that the operating system can properly store, organize, and retrieve files from disk devices. Partitioning allows better disk management, isolation of different system areas, and support for multiple operating systems or filesystems on a single disk.

Key Concepts

In Linux, storage devices such as hard drives and SSDs must be prepared before they can be used to store files. This preparation involves two major steps:

Partitioning – A physical disk can be divided into smaller, logical units called partitions. Each partition acts as a separate, manageable section of the disk. This allows for better organization, isolation between system and user data, support for multiple operating systems, or even different filesystem types on the same disk. Common partitioning tools include:

  • fdisk – for creating and managing MBR (Master Boot Record) partitions
  • gdisk – for handling GPT (GUID Partition Table), which supports more partitions and larger disks than MBR
  • parted – a flexible tool that works with both MBR and GPT formats, and allows resizing

Creating Filesystems – Once a partition is created, it must be formatted with a filesystem before it can store data. A filesystem defines how files are named, stored, and retrieved. Popular Linux filesystems include:

  • ext2, ext3, ext4 – traditional Linux filesystems, with ext4 being the most commonly used due to its balance of performance and stability
  • XFS – a high-performance journaling filesystem ideal for large files
  • VFAT and exFAT – used primarily for compatibility with Windows systems and external drives
  • Btrfs – a next-generation filesystem supporting advanced features like snapshots, compression, and multi-device spanning

The mkfs (make filesystem) command suite is used to create filesystems:

  • mkfs.ext4 /dev/sda1
    – formats a partition with the ext4 filesystem
  • mkfs.xfs /dev/sdb1
    – creates an XFS filesystem on the given partition

Each partition becomes a usable storage area once it has been formatted with a filesystem. This enables Linux to store, organize, and access files efficiently.

Partitioning Tools

  • fdisk – A command-line utility used for creating and modifying MBR (Master Boot Record) partition tables. It's best suited for older systems or disks smaller than 2 TB. It presents an interactive interface where users can create, delete, and manage partitions.
  • gdisk – A counterpart to fdisk but for GPT (GUID Partition Table) systems, which support larger disk sizes and more partitions. It provides similar functionality to fdisk but operates with GPT structure.
  • parted – A versatile and scriptable partition editor that supports both MBR and GPT formats. It can handle advanced operations like resizing and moving partitions and is often used for modern setups and automation scripts.

Creating Filesystems

  • mkfs.ext4 /dev/sdb1
    – This command formats the /dev/sdb1 partition with the ext4 filesystem, which is the default and most commonly used Linux filesystem known for stability and performance.
  • mkfs.xfs /dev/sdb2
    – Formats /dev/sdb2 with the XFS filesystem, which is optimized for high-performance operations, particularly with large files and parallel I/O.
  • mkfs.vfat /dev/sdb3
    – Formats the partition with the VFAT filesystem, which is compatible with DOS/Windows systems and is commonly used on USB drives and external media.
  • mkfs.exfat /dev/sdb4
    – Used to format the partition with exFAT, a modern Microsoft filesystem designed for flash storage that supports large files (over 4 GB) and is compatible with many operating systems.

Special Mention – Btrfs

Btrfs (B-tree File System) is a modern copy-on-write (CoW) filesystem developed to address the lack of pooling, snapshots, checksums, and integral multi-device spanning in traditional Linux filesystems.

  • Compression: Btrfs supports transparent file compression, which saves disk space by reducing the size of stored files without user intervention. Common algorithms include zlib, lzo, and zstd.
  • Multi-device Filesystems: Btrfs can combine multiple physical devices into a single logical volume, offering features like RAID 0, 1, 10, and RAID 5/6 (with caution in production).
  • Subvolumes: Subvolumes act like independent filesystems within Btrfs, useful for organizing data and enabling snapshots. Snapshots of subvolumes can be created for backup and rollback purposes.

Commands:

  • mkfs.btrfs /dev/sdX
    – Create a new Btrfs filesystem
  • btrfs subvolume create /mnt/my_subvol
    – Create a subvolume
  • btrfs filesystem df /mnt
    – View disk usage information
  • btrfs balance start /mnt
    – Balance data across devices

Practice Questions

  1. What command would you use to create a GPT partition table on /dev/sdc?
    a) fdisk /dev/sdc
    b) mkfs.gpt /dev/sdc
    c) parted /dev/sdc mklabel gpt
    d) mkfs -t gpt /dev/sdc
    Correct Answer: c
  2. How do you format a partition with the ext3 filesystem?
    a) mkfs.ext2 /dev/sdb1
    b) mkfs.ext4 /dev/sdb1
    c) mkfs.vfat /dev/sdb1
    d) mkfs.ext3 /dev/sdb1
    Correct Answer: d

Topic 104.2: Maintain the Integrity of Filesystems

What is Maintaining the Integrity of Filesystems?

"Maintain the Integrity of Filesystems" means ensuring that the filesystem remains healthy, consistent, and free of errors over time. Filesystems can sometimes develop problems due to improper shutdowns, hardware issues, or software bugs. Maintaining integrity involves:

  • Verifying Filesystem Health: Regularly checking filesystems for errors or corruption using tools like fsck for ext filesystems or xfs_repair for XFS.
  • Monitoring Disk Space and Inodes: Keeping an eye on available disk space and the number of free inodes (which track files) to avoid issues caused by a full or nearly full filesystem.
  • Repairing Filesystem Problems: Fixing detected errors to prevent data loss or system crashes.

This maintenance is critical to ensure reliable data storage, system stability, and smooth operation.

Key Concepts

As Linux systems run over time, filesystems can develop inconsistencies or errors due to sudden shutdowns, hardware failures, or disk issues. These inconsistencies can lead to data corruption or system instability if left unchecked. To prevent this, Linux offers a set of robust tools for verifying, monitoring, and repairing filesystems. System administrators must regularly assess filesystem integrity, especially after unclean shutdowns or when error messages appear during boot. The integrity of a filesystem is crucial for the overall health of the system. Using tools like fsck (Filesystem Check), administrators can scan partitions and fix detected problems. Commands like df and du help monitor available space and inode usage, ensuring that the filesystem doesn't run out of resources. For XFS filesystems, specialized tools like xfs_repair, xfs_fsr, and xfs_db are available for both diagnostics and repair operations. Consistent monitoring and occasional maintenance checks can prevent bigger problems and ensure that file operations remain stable, secure, and efficient.

Monitoring Tools

  • df -h
    : This command displays the amount of disk space used and available on all mounted filesystems in a human-readable format (e.g., GB, MB). It helps system administrators quickly see how much free space remains on each mounted partition, which is crucial to prevent disks from filling up.
  • du -sh /var
    : The du (disk usage) command reports the total disk space used by the /var directory (or any specified directory). The -s flag summarizes the total size, and -h makes the output human-readable. This is useful for checking which directories consume the most space, assisting in space management.
  • tune2fs -l /dev/sda1
    : This command lists detailed information about the ext2/ext3/ext4 filesystem on the specified device /dev/sda1. It includes data such as filesystem creation time, block count, inode count, mount count, and maximum mount count before a forced check, among others. This information helps in managing filesystem parameters and scheduling maintenance tasks.

Integrity and Repair

  • fsck (Filesystem Consistency Check): fsck is the general Linux command used to check and repair inconsistencies in filesystems. When the system detects potential corruption—such as after an improper shutdown—fsck scans the filesystem's metadata and data structures to find errors. It can fix issues like orphaned inodes, incorrect block counts, or directory entry problems. It works on many types of filesystems but often calls filesystem-specific tools internally.
  • e2fsck (Ext Filesystem Check): This tool is specifically designed to check and repair ext2, ext3, and ext4 filesystems. It is the filesystem-specific backend for fsck when dealing with ext filesystems. e2fsck performs detailed consistency checks and repairs, such as verifying inode tables, superblock integrity, block group descriptors, and directory structures. It's essential for maintaining the health of ext-based filesystems.
  • xfs_repair (XFS Filesystem Repair): XFS is a high-performance journaling filesystem commonly used in enterprise environments. xfs_repair is the dedicated tool to check and repair XFS filesystems. Unlike ext filesystems, XFS uses journaling and has different internal structures, so it requires its own repair utility. This tool scans the filesystem metadata and attempts to fix corruption without data loss.
  • xfs_fsr (XFS Filesystem Defragmenter): Although not a repair tool, xfs_fsr is used to defragment XFS filesystems, improving performance by reorganizing fragmented files into contiguous blocks. Defragmentation can help prevent performance degradation, which indirectly supports filesystem integrity by reducing wear on the storage device.
  • xfs_db (XFS Debugger): This utility is used for detailed inspection and debugging of XFS filesystems. It provides a low-level interface to view filesystem metadata and diagnose complex issues. While not typically used for routine repairs, it's valuable for advanced troubleshooting by system administrators and developers.

Each of these tools plays a vital role in ensuring filesystems remain consistent, recoverable, and performant. Regular use of fsck or its filesystem-specific counterparts, especially after improper shutdowns or detected errors, helps prevent data loss and maintain system stability.

Practice Questions

  1. Which command is specifically used to check and repair ext2, ext3, and ext4 filesystems?
    a) fsck
    b) e2fsck
    c) xfs_repair
    d) xfs_db
    Correct Answer: b) e2fsck
  2. Which tool is used to repair XFS filesystems?
    a) fsck
    b) e2fsck
    c) xfs_repair
    d) tune2fs
    Correct Answer: c) xfs_repair

Topic 104.3: Control Mounting and Unmounting of Filesystems

What is Control Mounting and Unmounting of Filesystems?

"Control Mounting and Unmounting of Filesystems" refers to the processes by which filesystems are made accessible (mounted) or inaccessible (unmounted) in a Linux system.

Mounting is the act of attaching a filesystem located on a storage device (like a partition or external drive) to a specific directory in the Linux directory tree, making the data accessible to the system and users.

Unmounting is the process of safely detaching that filesystem from the directory tree, ensuring that all data is written and no processes are using it before it's removed.

Controlling mounting and unmounting involves both manual commands and automatic configurations:

  • Manually mounting and unmounting filesystems using commands like mount and umount
  • Configuring filesystems to mount automatically at boot by editing the /etc/fstab file
  • Using device identifiers such as UUIDs or labels to reliably mount devices, regardless of device name changes
  • Managing removable devices that users can mount themselves
  • Being aware that systemd can manage mount units for more advanced and dynamic mounting control

This control is critical for system stability, data integrity, and user access to storage resources.

Key Concepts

Mounting filesystems is the process of making a filesystem accessible to the operating system by attaching it to a specific directory within the directory tree. Without mounting, the data stored on a disk partition or device remains inaccessible. When you mount a filesystem, you essentially "connect" that filesystem to a directory called a mount point (e.g., /mnt/data or /media/usb). Once mounted, the contents of the filesystem appear as if they are part of the directory tree starting at the mount point.

Mounting can be done manually using commands like

mount /dev/sdb1 /mnt/data

, which mounts the device /dev/sdb1 at /mnt/data until the system is rebooted or the filesystem is unmounted.

For automatic mounting at boot, Linux uses the /etc/fstab file. This file lists devices or filesystems and their associated mount points and options. During boot, the system reads /etc/fstab and mounts the listed filesystems automatically. Instead of referring to devices by their names like /dev/sdb1 (which can change based on hardware detection order), it's more reliable to use UUIDs (Universally Unique Identifiers) or labels to identify partitions. UUIDs and labels are unique identifiers stored within the filesystem metadata, so even if device names change, the correct filesystem is mounted. Using UUIDs and labels helps prevent mounting errors and ensures the right filesystems are attached at the correct mount points consistently.

Manual Mounting and Unmounting of Filesystems in Linux

Mounting a filesystem means attaching it to a directory (known as a mount point) so the system can access the files and directories stored on that device. Without mounting, the data on the device remains inaccessible to the operating system and users.

The command

mount /dev/sdb1 /mnt

attaches the filesystem found on the device /dev/sdb1 to the directory /mnt. After this command, the contents of /dev/sdb1 will be accessible through the /mnt directory.

The /dev/sdb1 refers to the first partition on the second SCSI/SATA disk detected by Linux. Devices are named this way in Linux (/dev/sda, /dev/sdb, etc.), and partitions are numbered starting at 1. The mount point /mnt is just a regular directory, typically empty and used temporarily to access other filesystems. Unmounting is the process of detaching the filesystem from the mount point, making it no longer accessible. This is done with the command:

umount /mnt

– This command detaches the filesystem mounted at /mnt. Once unmounted, the files and directories previously accessible through /mnt are no longer available.

Unmounting is necessary before physically removing devices (like USB drives) to ensure all data is written and the filesystem is not corrupted.

Persistent Mounting

/etc/fstab – This is a critical configuration file in Linux that contains instructions on which filesystems should be mounted automatically at boot time. It specifies the device or UUID, the mount point (directory), filesystem type, mount options, and dump/pass settings for filesystem checks. Proper configuration of /etc/fstab ensures that all necessary filesystems are available immediately after the system boots without manual intervention.

Tools to Identify Devices and Partitions

  • lsblk (List Block Devices): This command lists all available block devices (disks, partitions, and removable media) in a tree-like format. It shows device names, types, sizes, and mount points, helping you quickly understand the disk layout and which devices are currently mounted.
  • blkid (Block ID): This command prints detailed information about block devices, such as their UUIDs (Universally Unique Identifiers), labels, and filesystem types. Using UUIDs or labels for mounting filesystems (instead of device names like /dev/sdb1) is more reliable because device names can change after reboot or when hardware is added or removed.

Default Mount Points

/media/ Directory: This is the conventional directory where Linux systems automatically mount removable media like USB drives, CDs, and external hard drives when they are plugged in. Many desktop environments and automounters use this directory to provide easy access to removable devices.

Systemd Mount Units

Modern Linux systems that use systemd as the init system can manage mounts via mount units. These are systemd service units that handle mounting filesystems dynamically with more control, dependencies, and parallelization during boot or runtime. Using systemd mount units can be an alternative or complement to traditional /etc/fstab configuration, especially for complex or conditional mounts.

Practice Questions

  1. Which file is used to configure automatic mounting of filesystems at boot in Linux?
    a) /etc/mtab
    b) /etc/fstab
    c) /etc/hosts
    d) /etc/mount.conf
    Correct Answer: b) /etc/fstab
  2. Which command option allows you to mount a filesystem using its UUID?
    a) mount -u UUID=<uuid> /mnt
    b) mount UUID=<uuid> /mnt
    c) mount -U <uuid> /mnt
    d) mount -uuid <uuid> /mnt
    Correct Answer: b) mount UUID=<uuid> /mnt

Topic 104.5: Manage File Permissions and Ownership

What is Manage File Permissions and Ownership?

Manage File Permissions and Ownership refers to controlling who can access and modify files and directories in a Linux system. Every file and directory has an owner (a user) and a group, and permissions determine what actions these users and groups can perform.

Key Points:

  • Permissions define read (r), write (w), and execute (x) rights for the owner, group, and others
  • Ownership links files to a specific user and group
  • Special permission bits like SUID, SGID, and the sticky bit add additional security controls
  • The umask controls the default permissions for newly created files and directories

Commands:

  • chmod changes the permissions of files or directories
  • chown changes the ownership (user)
  • chgrp changes the group ownership
  • umask sets default permission masks for new files

This management is essential for system security and ensuring proper access control across users and processes.

Key Concepts

Permissions in Linux form the core of the system's security framework. Each file and directory is associated with an owner (a specific user) and a group, and permission bits that specify what kind of access is allowed. These permissions are divided into three categories: owner permissions, group permissions, and others (everyone else). Each category can have read (r), write (w), and execute (x) permissions set or denied. This model ensures that users can only access or modify files and directories as allowed, helping to protect data integrity and system security.

Basic Tools

  • chmod (Change Mode): This command changes the permission bits of files and directories. Permissions control who can read, write, or execute a file. For example,
    chmod 755 filename
    sets the file to be readable and executable by everyone, but only writable by the owner.
  • chown (Change Owner): This command changes the ownership of a file or directory to a different user. For example,
    chown alice file.txt
    changes the owner of file.txt to user alice.
  • chgrp (Change Group): This command changes the group ownership of a file or directory. For example,
    chgrp developers file.txt
    assigns the file to the group named developers. This affects group permissions.
  • umask (User Mask): This is a setting that determines the default permission bits assigned to newly created files and directories. It acts as a filter that removes permissions from the system default. For example, a umask of 022 results in new files being created with permissions 644 (rw-r--r--) and directories with 755 (rwxr-xr-x).

Special Permissions

Linux permissions are not limited to the basic read (r), write (w), and execute (x) bits. There are also special permission bits that add more control and flexibility over how files and directories behave. These special bits are SUID, SGID, and the Sticky Bit.

1. SUID (Set User ID)

  • When the SUID bit is set on an executable file, any user who runs that file temporarily gains the permissions of the file's owner during the execution.
  • This is useful for programs that require elevated privileges to perform specific tasks, even when run by normal users.
  • Example: The passwd command, which allows users to change their passwords, runs with root privileges via the SUID bit.
  • How it looks: When you run ls -l, a file with SUID set might show permissions like -rwsr-xr-x (the s replaces the x in the owner's execute position).

2. SGID (Set Group ID)

  • When set on an executable file, it works similarly to SUID but grants the permissions of the file's group during execution.
  • When set on a directory, all files created within inherit the directory's group ownership, rather than the user's primary group.
  • This helps maintain consistent group ownership in shared directories.
  • Example: In collaborative projects, SGID on a directory ensures all new files belong to the same group.
  • How it looks: Permissions like drwxrwsr-x for directories or -rwxr-sr-x for files, with s replacing x in the group execute position.

3. Sticky Bit

  • Mostly used on directories, the sticky bit restricts deletion or renaming of files inside that directory.
  • Only the file's owner, directory's owner, or root can delete or rename files, even if other users have write permissions on the directory.
  • This is crucial in shared directories like /tmp to prevent users from deleting or tampering with others' files.
  • How it looks: Permissions like drwxrwxrwt, where the t replaces the execute bit for others.

These special bits provide enhanced security and control over how files and directories behave in multi-user environments, helping protect sensitive operations and shared resources.

Practice Questions

  1. What does the command chmod 4755 file do?
    a) Sets the file to be readable, writable, and executable by all users
    b) Sets the SUID bit and permissions to rwxr-xr-x on the file
    c) Changes the file owner to user ID 4755
    d) Removes all permissions from the file
    Correct Answer: b
  2. How do you change the owner of a file to john?
    a) chmod john filename
    b) chown john filename
    c) chgrp john filename
    d) usermod john filename
    Correct Answer: b

Topic 104.6: Create and Change Hard and Symbolic Links

What is Create and Change Hard and Symbolic Links?

"Create and Change Hard and Symbolic Links" refers to managing two types of links in Linux filesystems that provide alternate ways to access files.

Hard Links: These are direct references to the inode (the actual file data on disk). Multiple hard links to the same file share the same inode, so they are essentially equal pointers to the same data. Deleting one hard link does not delete the data until all hard links are removed.

Symbolic Links (Soft Links): These are special files that act as pointers or shortcuts to another file or directory path. Unlike hard links, symbolic links have their own inode and can cross filesystem boundaries.

Creating and managing these links allows system administrators to organize files efficiently, maintain compatibility, and provide flexible access paths without duplicating data.

Common commands involved:

  • ln — to create hard and symbolic links (with -s option for symbolic links)
  • ls -l — to list files and show which are links

Key Concepts

Links in Linux provide a way to create multiple access points or references to the same file or directory. There are two main types of links:

Hard links: These are multiple directory entries that point directly to the same file data on disk. Essentially, hard links are different filenames that share the same underlying inode (the filesystem's representation of the file). This means changes to the file via any hard link affect the same data, and the file remains accessible as long as at least one hard link exists. Hard links cannot span different filesystems or link to directories.

Symbolic (soft) links: These are special files that contain a pathname referencing another file or directory. Symbolic links act like shortcuts and can point to files or directories across different filesystems. If the original file is moved or deleted, the symbolic link becomes broken (dangling) and points to a non-existent target.

Using links increases flexibility and consistency in system configuration and file management, allowing easier organization, backup, or sharing of files without duplication of data.

Creating Links

  • Hard Links (
    ln file1 file2
    ): This command creates a hard link named file2 that points to the same inode as file1. Both file1 and file2 are equally valid names for the same data on disk. Changes made through either filename affect the same content, and the file only gets deleted when all hard links to it are removed. Hard links cannot cross filesystem boundaries and cannot link to directories.
  • Symbolic (Soft) Links (
    ln -s /etc/httpd/conf /home/user/httpd_conf
    ): This command creates a symbolic link called httpd_conf in /home/user that points to the original /etc/httpd/conf directory or file. Symbolic links are separate files containing a path to the target and can link across filesystems or to directories. If the target is moved or deleted, the symbolic link becomes broken.

These linking methods enable flexible file management, allowing multiple references to files without duplication, which is useful in administration, backups, and system configuration.

Key Differences

Feature Hard Link Symbolic (Soft) Link
Pointer Type Points directly to the file's inode Contains a pathname to the target file or directory
Link Target Only files (not directories) Files or directories
Cross Filesystem Linking Not allowed Allowed
Effect of Target Deletion File remains accessible as long as one hard link exists Link becomes broken (dangling) if target is deleted or moved
Storage No additional storage; just another directory entry Uses disk space as it stores the path string
Usage For creating multiple file names referencing same data Like shortcuts or references to original files/directories
Identification ls -li shows same inode number for all hard links Different inode number; link shown with l in permissions

Practice Questions

  1. How do you create a symbolic link named shortcut to /usr/bin/python?
    a) ln /usr/bin/python shortcut
    b) ln -s /usr/bin/python shortcut
    c) ln -h /usr/bin/python shortcut
    d) ln -l /usr/bin/python shortcut
    Correct Answer: b
  2. Which command helps you differentiate between hard and symbolic links by showing inode numbers?
    a) ls -l
    b) ls -s
    c) ls -li
    d) ls -a
    Correct Answer: c

Topic 104.7: Find System Files and Place Files in the Correct Location

What is Find System Files and Place Files in the Correct Location?

"Find System Files and Place Files in the Correct Location" refers to the practice of locating important files on a Linux system and understanding the correct directories where different types of files should reside according to Linux conventions.

This involves two main parts:

Finding system files: Using commands like find, locate, whereis, which, and type to search for files or commands on the system. For example, if you need to find the location of a configuration file or an executable, these tools help you locate them quickly.

Placing files correctly: Linux follows the Filesystem Hierarchy Standard (FHS) which defines standard directories and their intended use. For example:

  • /bin and /sbin for essential binaries
  • /etc for configuration files
  • /usr for user applications and libraries
  • /var for variable data like logs
  • /home for user directories
  • /tmp for temporary files

Knowing where to place files ensures system organization, consistency, and proper functioning of software.

Key Concepts

Linux systems organize files and directories according to a well-defined standard called the Filesystem Hierarchy Standard (FHS). This standard dictates where different types of files should reside, making the system more predictable and easier to manage. Understanding the FHS helps in two major ways:

Placing Files Correctly: When you install software, create scripts, or manage configurations, placing files in the correct directories according to FHS ensures that the system can find and use them properly. For example, executable binaries typically go in /usr/bin or /bin, configuration files belong in /etc, and user data should be placed in /home.

Troubleshooting: Knowing the standard locations of system files and directories makes it easier to diagnose and fix issues. For instance, if a service isn't working, you know to check its config files in /etc, its logs in /var/log, or its runtime data in /var/run.

In summary, the FHS provides a consistent framework for file placement, enhancing system organization, usability, and maintainability.

Important Directories

  • /bin and /sbin - These directories contain essential binary executables (programs) that are required for the system to boot, repair, and run in single-user mode.
    • /bin holds essential user commands needed by all users, like ls, cp, mv, and bash
    • /sbin holds essential system binaries, generally for system administration, like fsck, ifconfig, and reboot. Typically, /sbin commands require root privileges
  • /etc - This directory stores system-wide configuration files. It contains settings and configuration files that control how the system and services operate. Examples include network configurations, user account information (/etc/passwd), and service startup scripts.
  • /usr - /usr is for user-related programs and data. It holds installed software applications, libraries, and documentation.
    • /usr/bin contains most user commands and applications
    • /usr/lib contains libraries for those programs
    • /usr/share holds architecture-independent files like documentation, icons, and locale data
  • /var - Stands for variable data. This directory contains files that are expected to grow and change during system operation, such as log files (/var/log), spool files (print queues), and temporary files that must persist between reboots.
  • /home - This directory holds personal directories for users. Each user's personal files, documents, downloads, and settings reside here, e.g., /home/john.
  • /tmp - Used for temporary files created by programs and users during runtime. Files here are usually deleted upon reboot or after a certain time.

Together, these directories form the core structure that helps keep Linux systems organized, predictable, and maintainable. Understanding what each directory is for helps in system management, troubleshooting, and ensuring files are placed correctly following the FHS.

Finding Tools

  • find / -name filename - This command searches the entire filesystem (starting from /) for files that exactly match the given name (filename). It is very powerful and flexible, allowing you to search by name, size, modification date, ownership, and more. Because it searches the actual filesystem live, it can be slower on large systems but always up-to-date.
  • locate filename - This command searches for files matching filename using a pre-built database, usually updated daily by a background job (updatedb). Because it searches a database rather than the live filesystem, it is much faster than find but might not show the very latest changes or new files if the database is not updated.
  • which command - This command shows the full path of an executable program that would run if you typed the command name in the shell. It searches the directories listed in the PATH environment variable in order and returns the first match. For example, which ls might return /bin/ls.
  • whereis command - This command locates the binary, source, and manual page files for a given command. It searches a predefined set of directories and can be more comprehensive than which. For example, whereis ls might return /bin/ls /usr/share/man/man1/ls.1.gz.
  • type command - This shell builtin shows how a command name would be interpreted by the shell. It indicates if the command is a built-in shell command, an alias, a function, or an external executable. For example, type cd might say "cd is a shell builtin".

Together, these commands help users and administrators find files, executables, and commands quickly and accurately in a Linux system, aiding troubleshooting, scripting, and system management.

Practice Questions

  1. What command shows all directories where bash might be located?
    a) find / -name bash
    b) locate bash
    c) which bash
    d) whereis bash
    Correct answer: d) whereis bash
  2. Where would you store a custom application configuration file?
    a) /bin
    b) /etc
    c) /usr
    d) /var
    Correct answer: b) /etc

Quick Reference Commands

Partitioning and Filesystem Creation

  • fdisk /dev/sdX
    - Interactive tool to create/modify MBR partitions.
  • gdisk /dev/sdX
    - GPT partitioning tool similar to fdisk.
  • parted /dev/sdX
    - Flexible partitioning tool supporting MBR and GPT.
  • mkfs.ext4 /dev/sdXn
    - Create ext4 filesystem on partition.
  • mkfs.ext3 /dev/sdXn
    - Create ext3 filesystem on partition.
  • mkfs.xfs /dev/sdXn
    - Create XFS filesystem on partition.
  • mkfs.vfat /dev/sdXn
    - Create VFAT filesystem (for compatibility with Windows/DOS).
  • mkfs.exfat /dev/sdXn
    - Create exFAT filesystem (for flash drives, large files).
  • mkfs.btrfs /dev/sdXn
    - Create Btrfs filesystem.

Filesystem Integrity and Maintenance

  • fsck /dev/sdXn
    - Filesystem consistency check and repair.
  • e2fsck /dev/sdXn
    - Ext2/3/4 filesystem check and repair.
  • xfs_repair /dev/sdXn
    - Repair XFS filesystem.
  • xfs_fsr /dev/sdXn
    - Defragment XFS filesystem.
  • xfs_db /dev/sdXn
    - Debug XFS filesystem.
  • df -h
    - Show disk space usage in human-readable format.
  • du -sh /path
    - Show size of directory or file.
  • tune2fs -l /dev/sdXn
    - Display ext2/ext3/ext4 filesystem parameters.

Mounting and Unmounting Filesystems

  • mount /dev/sdXn /mount/point
    - Manually mount a filesystem.
  • umount /mount/point
    - Unmount a filesystem.
  • blkid
    - Display block device attributes (UUID, labels).
  • lsblk
    - List block devices and their mount points.
  • View/edit /etc/fstab - Configure filesystems to mount automatically at boot.

File Permissions and Ownership

  • chmod [options] mode file
    - Change file or directory permissions.
  • chown user[:group] file
    - Change owner and/or group of a file.
  • chgrp group file
    - Change group ownership of a file.
  • umask
    - View or set default file creation permissions mask.

Links Management

  • ln source target
    - Create a hard link.
  • ln -s source target
    - Create a symbolic (soft) link.
  • ls -li
    - List files with inode numbers to distinguish hard links.

Finding Files and Commands

  • find /path -name filename
    - Search for files by name.
  • locate filename
    - Quickly find files using an updated database.
  • updatedb
    - Update the locate database.
  • which command
    - Show full path of executable command.
  • whereis command
    - Locate binary, source, and manual for a command.
  • type command
    - Show how shell interprets a command (builtin, alias, etc).

Conclusion

Mastering storage devices, partitions, filesystems, and the Linux directory structure is non-negotiable for serious Linux users and administrators. Whether it's formatting a new disk, repairing a corrupted filesystem, or setting the right permissions, these skills form the backbone of Linux system management. The Filesystem Hierarchy Standard ensures everything is organized, consistent, and predictable. By consistently practicing these concepts and using the listed tools, you will build strong foundational skills essential for certifications like LPIC-1 and RHCSA, and more importantly, for real-world Linux administration.

Take the LPIC-1 Devices, Linux Filesystems, and Filesystem Hierarchy Standard Quiz Now