fsck

system managementLinux/Unix
The fsck command is one of the most frequently used commands in Linux/Unix-like operating systems. fsck Check and repair a Linux filesystem

Quick Reference

Command Name:

fsck

Category:

system management

Platform:

Linux/Unix

Basic Usage:

fsck [options] [arguments]

Common Use Cases

    Syntax

    fsck [options] [filesystem...]

    Options

    Option Description
    -A Check all filesystems listed in /etc/fstab
    -C Display progress bar while checking
    -N Don't execute, just show what would be done
    -R Skip the root filesystem when used with -A
    -T Don't show the title on startup
    -V Verbose mode, shows filesystem-specific commands
    -a Automatically repair the filesystem without asking
    -f Force checking even if the filesystem is clean
    -M Skip mounted filesystems
    -n Don't make any changes to the filesystem (answer 'no' to all questions)
    -r Interactive repair mode (ask before fixing)
    -t type Specify the filesystem type(s) to check
    -v Verbose mode, more details about the checking process
    -y Assume 'yes' to all questions (non-interactive mode)

    Examples

    How to Use These Examples

    The examples below show common ways to use the fsck command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.

    # Basic Examples Basic
    fsck /dev/sda1
    Check the filesystem on /dev/sda1.
    fsck -t ext4 /dev/sdb1
    Check the ext4 filesystem on /dev/sdb1.
    fsck -A
    Check all filesystems listed in /etc/fstab. # Advanced Examples Advanced fsck -vy /dev/sdc1 Check the filesystem with verbose output and automatically repair problems. fsck -AR -t ext4 Check all ext4 filesystems listed in /etc/fstab except the root filesystem. fsck -N -t ext4 /dev/sdb1 Show what would be done without actually checking the filesystem. fsck -M /dev/sdb1 Skip mounted filesystems to prevent data corruption. fsck -f /dev/sda3 Force checking even if the filesystem appears clean.

    Try It Yourself

    Practice makes perfect! The best way to learn is by trying these examples on your own system with real files.

    Understanding Syntax

    Pay attention to the syntax coloring: commands, options, and file paths are highlighted differently.

    Notes

    The fsck (filesystem check) command is used to check and optionally repair one or more Linux filesystems. It's a crucial system maintenance tool for ensuring filesystem integrity. Key features of fsck: 1. Filesystem Verification: fsck checks filesystems for inconsistencies, errors, and structural problems that might lead to data corruption or loss. 2. Repair Capabilities: It can repair many types of filesystem errors, either interactively (asking for confirmation) or automatically depending on the options used. 3. Multiple Filesystem Support: fsck is a frontend that calls filesystem-specific checkers (like e2fsck for ext2/3/4, xfs_repair for XFS, etc.) based on the filesystem type. 4. Boot-time Checking: Systems are often configured to run fsck during boot if a filesystem was not cleanly unmounted or after a certain number of mounts. 5. Interactive Options: fsck can run in various modes - fully automatic, fully interactive (asking before each repair), or non-interactive but showing what would be done. 6. Multiple Filesystem Check: With the -A option, fsck can check all filesystems listed in /etc/fstab, making system-wide checks convenient. 7. Safety Features: Options like -M prevent checking mounted filesystems, which could lead to data corruption if repairs were attempted on active filesystems. Important notes about fsck: 1. It's safest to run fsck on unmounted filesystems to prevent data corruption. 2. Root filesystems typically require the system to be booted in recovery mode or from a live CD/USB to be checked. 3. Modern journaling filesystems (like ext4, XFS, Btrfs) require fsck less frequently than older non-journaling systems. 4. The specific options available depend on the filesystem type being checked.

    Related Commands

    These commands are frequently used alongside fsck or serve similar purposes:

    Use Cases

    Learn By Doing

    The best way to learn Linux commands is by practicing. Try out these examples in your terminal to build muscle memory and understand how the fsck command works in different scenarios.

    $ fsck
    View All Commands