lsblk

disk managementLinux
The lsblk command is one of the most frequently used commands in Linux/Unix-like operating systems. lsblk List information about block devices

Quick Reference

Command Name:

lsblk

Category:

disk management

Platform:

Linux

Basic Usage:

lsblk [options] [arguments]

Common Use Cases

    Syntax

    lsblk [options] [device...]

    Options

    Option Description
    -a, --all Display all devices, including empty ones
    -b, --bytes Print sizes in bytes rather than human-readable format
    -d, --nodeps Don't print device holders or slaves (partitions)
    -e, --exclude list Exclude devices by major number
    -f, --fs Show filesystem information
    -i, --ascii Use ASCII characters for tree formatting
    -J, --json Use JSON output format
    -l, --list Use list format output
    -m, --perms Show permissions information
    -n, --noheadings Don't print headings
    -o, --output list Specify which output columns to print
    -p, --paths Print complete device paths
    -r, --raw Use raw output format
    -S, --scsi Output info about SCSI devices only
    -t, --topology Show topology information
    -x, --sort column Sort output by specified column

    Examples

    How to Use These Examples

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

    # Basic Examples Basic
    lsblk
    Display a tree of all block devices.
    lsblk /dev/sda
    List only the sda device and its partitions.
    # Advanced Examples Advanced
    lsblk -f Show filesystem information, including UUID and mount points. lsblk -o NAME,SIZE,FSTYPE,TYPE,MOUNTPOINT Display only the specified columns. lsblk -b Show sizes in bytes instead of human-readable format. lsblk -d Show only disk devices, not partitions. lsblk -S Show SCSI devices only. lsblk -J Output in JSON format. lsblk -x SIZE Sort output by device size. lsblk -m Show device owner, group and mode information.

    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 'lsblk' (list block devices) command is a utility for displaying information about all available or specified block devices on a Linux system. Block devices are storage devices like hard drives, SSDs, USB drives, and their partitions. Key features of the lsblk command: 1. Device Hierarchy: lsblk displays block devices in a tree-like structure, making it easy to visualize the relationship between disks and their partitions. 2. Detailed Information: The command can show a wide range of information about each device, including size, type, mountpoint, filesystem type, and more. 3. Format Flexibility: Output can be formatted as a tree (default), a simple list, or structured formats like JSON for easy parsing in scripts. 4. Filesystem Details: With the -f option, lsblk provides comprehensive filesystem information, including UUIDs and labels, which is valuable for system configuration. 5. Filtering Capabilities: Users can filter the output to show only specific devices or device types, making it easier to focus on relevant information. 6. Customizable Output: The -o option allows users to specify exactly which columns of information they want to see, creating tailored outputs for specific needs. 7. Integration with System Tools: lsblk is often used in system scripts and by other utilities to gather storage information. Common use cases for lsblk include: - Identifying all storage devices connected to a system - Determining the relationship between physical disks and their partitions - Checking which partitions are mounted and where - Gathering filesystem information for system configuration - Troubleshooting storage-related issues - Scripting automated system management tasks lsblk is part of the util-linux package and is available on most Linux distributions by default. It reads information directly from the Linux kernel's sysfs filesystem, providing accurate and up-to-date information about the system's block devices. The command is particularly useful for system administrators who need to manage storage devices, but it's also valuable for regular users who want to understand their system's storage configuration or troubleshoot issues related to disk drives and partitions.

    Related Commands

    These commands are frequently used alongside lsblk 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 lsblk command works in different scenarios.

    $ lsblk
    View All Commands