lsblk
lsblk
The lsblk
command in Unix and Linux is used to list information about all available or the specified block devices. It provides a tree-like structure of storage devices, including information such as the device name, major and minor device numbers, size, type, and mount points. This command is particularly useful for system administrators when managing and configuring disk partitions and other block devices.
Basic Usage
The basic syntax for lsblk
is:
device
: The specific device to query. If omitted,lsblk
lists all block devices.
Examples
List All Block Devices
To list all block devices:
List Detailed Information
To list detailed information, including file system type and mount points:
List All Devices Including Empty Devices
To include empty devices in the output:
List Devices in JSON Format
To list devices in JSON format, which can be useful for scripting:
List Specific Device
To list information about a specific device, such as /dev/sda
:
Options
-a
: Include empty devices.-b
: Print sizes in bytes rather than in a human-readable format.-d
: Print only the device name without any partition information.-e
: Exclude devices with specified major numbers.-f
: Print file system information.-h
: Print a help message and exit.-J
: Use JSON output format.-l
: Use list format output.-m
: Print minimum I/O size, optimal I/O size, and physical sector size.-n
: Do not print the header line.-o
: Specify which columns to print.-P
: Use pairs format output.-r
: Print raw output without tree formatting.-t
: Print the topology information.-x
: Print exclusive device information.
Practical Use Cases
Checking Disk Layout
To understand the layout of your disk, including partitions and mount points:
Verifying Filesystem Information
To verify the file system type and UUID of your devices:
Scripting and Automation
To use the output in scripts, especially when needing JSON format:
Excluding Specific Devices
To exclude certain devices, like loop devices, from the output:
Examples with Explanations
Displaying Full Disk Information
To display all block devices with detailed information about file systems:
-a
: Includes empty devices.-f
: Shows file system information.
Using Specific Columns
To display only specific columns, such as name, size, and mount points:
-o
: Specifies the columns to print.
JSON Output for Automation
To get the output in JSON format for further processing in scripts:
-J
: Uses JSON output format.
Summary
The lsblk
command is a powerful tool for listing information about block devices in Unix and Linux systems. It provides a clear overview of the storage devices, their partitions, file systems, and mount points. Mastering lsblk
helps in effectively managing and troubleshooting storage-related issues, making it an essential command for system administrators.
help
Last updated