Lsblk Command - List Block Devices | Online Free DevTools by Hexmos

List block devices with the lsblk command. Explore options for detailed output, human-readable sizes, UUIDs, labels, and JSON format for system analysis.

Lsblk Command

Understanding the lsblk Command

The lsblk command is a powerful utility in Linux and Unix-like operating systems used to list information about all available block devices. Block devices include hard drives, SSDs, USB drives, CD-ROM drives, and partitions. It presents this information in a tree-like format, making it easy to visualize the relationships between devices and their partitions.

Key lsblk Command Options

Here are some of the most useful options for the lsblk command:

Listing All Block Devices

To see all block devices, including those that might not be mounted or have filesystems, use the -a flag.

lsblk -a

Displaying Detailed Information

The -f option displays filesystem type, UUID, and mount point information for each device. This is crucial for understanding how your storage is organized and mounted.

lsblk -f

Human-Readable Sizes

For easier interpretation of disk sizes, use the -h flag to display sizes in human-readable formats (e.g., KB, MB, GB, TB).

lsblk -h

Showing Full Device Paths

The -p option displays the full device path for each block device, which can be useful for scripting or referencing devices directly.

lsblk -p

Including All Available Information

Use the -O flag to output all available columns of information about devices, including details about RAIDs and vendor-specific information.

lsblk -O

Excluding Specific Device Types

You can exclude certain device types using the -e option followed by the major device numbers to ignore. For example, to exclude loop devices (major number 7):

lsblk -e 7

To exclude multiple types, separate their major numbers with commas:

lsblk -e 7,1

JSON Output Format

For programmatic use or integration with other tools, the -J option outputs the block device information in JSON format.

lsblk -J

Script-Friendly Output

The -n option provides a "noheadings" output, which is useful for scripts where you only need the raw data without column headers.

lsblk -n

Customizing Output Columns

You can specify which columns to display using the -o option. For example, to show only the name, size, UUID, and label:

lsblk -o NAME,SIZE,UUID,LABEL

Topology Information

The -t option displays topology information for the block devices, which can be helpful for understanding performance characteristics.

lsblk -t

External Resources