How to List All Block Devices in Linux | lsblk Command
Last Updated :
18 Jan, 2024
Understanding the storage devices connected to your Linux system is crucial for efficient system management. The lsblk
command, short for “list block devices,” is a powerful tool that provides detailed information about block devices such as hard drives, solid-state drives, and other storage-related devices. In this article, we will delve into the lsblk
command, exploring its syntax, options, and practical implementations.
In other words, Lsblk is used to display details about block devices and these block devices(Except ram disk) are basically those files that represent devices connected to the pc. It queries /sys virtual file system and udev db to obtain information that it displays. And it basically displays output in a tree-like structure. This command comes pre-installed with the util-Linux package.Â
Installing lsblk Command in Linux
Many Linux distributions do not have lsblk command pre-installed. To install it use the following commands as per your Linux distribution.Â
In case of Debian/Ubuntu Â
sudo apt-get install util-linux
In case of CentOS/RedHat Â
sudo yum install util-linux-ng
In case of Fedora OSÂ Â
sudo yum install util-linux-ng
Syntax of lsblk Command in Linux
The basic syntax of the lsblk
command is simple:
lsblk [OPTIONS] [DEVICE...]
Here,
[OPTIONS]
represents the various flags and parameters that can be used with the command.
[DEVICE...]
refers to the specific block devices you want to list. If no device is specified, lsblk
will display information for all available block devices.
Options Available in lsblk Command
Display all devices, including empty ones.
|
Print sizes in bytes instead of the more human-readable formats.
|
Invert the output, showing only non-empty devices.
|
Print output in a list format.
|
Define the output columns to display.
|
Display key-value pairs for each device.
|
Print devices in a tree-like format.
|
Exclude devices that match the specified criteria.
|
Practical Example of lsblk Command in Linux :
How to List All Block Devices in Linux
To display block devices.Â
lsblk
This command will display a hierarchical view of all block devices connected to your system, including information about partitions and mount points.
How to Display All Devices, Including Empty Ones
To display empty block devices as well. Â
lsblk -a
This command includes all devices, even empty ones, in the output. It can be useful when you want to see all available devices, including those without any partitions or mount points.
To print size information in bytes.Â
lsblk -b
The -b
option displays sizes in bytes. This can be handy when you need precise size information for block devices.
The -t
option organizes devices in a tree-like format, making it easier to visualize the relationships between devices and partitions.
lsblk -t
viewing devices in tree-like format
To print zone model for devices. Â
lsblk -z
To skip slave entries
lsblk -d
This will skip all the slave entries.Â
How to Invert the output, showing only non-empty devices
To use ASCII characters for tree formatting. Â
lsblk -i
Inverting the output with -i
will show only non-empty devices. This is useful when you want to focus on devices with existing partitions or mount points.
This will display all details of device owner, group and mode of block devices.Â
lsblk -m
How to Define the output columns to display
To print selected columns of block-devices.Â
lsblk -o SIZE, NAME, MOUNTPOINT
Use -o
to customize the output columns. In this example, we specify that we only want to see the device name, size, and mount point for each device.
This will print only the specified columns.Â
To hide column headings
This will hide column headings.Â
lsblk -dn
To display help section of the command
lsblk --help
This will display the help section of the command.
Conclusion
In this article we discussed the lsblk command which is a vital tool for managing storage devices in Linux, offering detailed insights into hard drives and SSDs. This article covers its syntax, options, and practical applications. Lsblk, part of the util-Linux package, efficiently queries system files to present a tree-like view of block devices. From installation on various Linux distributions to understanding syntax and options, this guide provides a comprehensive overview. Examples demonstrate how to list devices, customize output, and visualize storage efficiently. Mastering lsblk enhances system administration, allowing users to navigate and manage storage resources effectively.
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...