How to Use the lsblk Command to List Block Devices on Linux
As a Linux user, you might often need to list the hardware devices connected to your system. This information can be useful when troubleshooting or configuring your system. The lsblk command is a powerful tool that allows you to list all the block devices connected to your Linux system, which includes hard disks, flash drives, and memory cards.
In this article, we’ll explore how to use the lsblk command to list block devices on Linux.
Syntax
The syntax of the lsblk command is relatively simple:
lsblk [OPTIONS] [DEVICE]
Here, the OPTIONS are any command-line options you would like to use while running the command, and DEVICE refer to any block devices you want to list.
To list all block devices on your Linux system, simply run the lsblk command without any options or arguments, like this:
$ lsblk
The above command will list all available block devices on your system, including their names, sizes, and mount points.
Options
There are several options available with the lsblk command, which can help you narrow down your search for certain devices. Here are some of the commonly used options:
-a or –all: Show all block devices, including empty ones.
-b or –bytes: Show size in bytes instead of the default human-readable format.
-f or –fs: Show the filesystem type of each device.
-h or –human-readable: Show the size of the device in human-readable format.
-i or –inverse: Invert the output, showing only empty devices.
-m or –ascii: Use ASCII characters to draw the tree view.
-p or –paths: Print each device with its full absolute path.
-t or –topology: Show the relationship between parent and child devices.
-u or –uniq: Show only unique devices, filtering out duplicate names.
-x or –exclude: Exclude any devices matching a specified pattern.
Examples
Here are some examples of how to use the lsblk command in Linux:
To list all block devices on your system:
$ lsblk
To list all block devices with their filesystem type:
$ lsblk -f
To list all block devices with their size in human-readable format:
$ lsblk -h
To list all block devices and their mount points:
$ lsblk -m
To list all block devices in a tree view:
$ lsblk -t
To list all SCSI devices, excluding partition names:
$ lsblk -x NAME_REGEX=’sd[a-d][^0-9]’
Conclusion
The lsblk command is a powerful tool that can help you list all block devices on your Linux system. With the various options available, you can specify your search criteria and view the output in a way that suits you. Next time you need to list hardware devices on your Linux system, use the lsblk command to get fast and accurate results.