The lsblk (pronounced “L-S-block”) command is commonly used to get the list of all the block devices in your system with their information, such as size, type, mount point, etc.
If you are wondering, what are block devices? Then it’s basically files that represent the device connected to your system (except for ram disk).
In this article, you will learn how to list out and get information about all the block devices using the lsblk command and its options (with practical examples).
|Lists Information about Block Devices.
|Root or Sudo Privileges
|Ubuntu, Manjaro, Fedora, etc.
Syntax of the lsblk Command
The lsblk command takes two arguments: one is the option, and the other is the block device name (both are optional).
$ lsblk [OPTION] [DEVICE...]
When you execute this command without any options or arguments, you will get the list of all the block devices in a tree-like format.
The following is an explanation of each field mentioned in the above output:
NAME: Device name
MAJ:MIN: Major and minor device numbers:
RM: Indicates the removable device with “1” and non-removable device with “0“.
SIZE: Device size in human-readable format, i.e., K, M, G, T, etc.
RO: Indicates the read-only status with “1” and not read-only status with “0“.
TYPE: Device type, i.e., disk, loopback device, partition, or LVM device.
MOUNTPOINT: Mount point to which the referenced device is mounted.
The following is an explanation of each device you will see in the output:
- Loopback devices: It represents the ISO image, disk image, file system, or logical volume image and assign them in loop0, loop1, loop2, etc.
- CD-ROM: It mainly indicates CD/DVD in the sr0 or sr1 format.
- Disk partitions: It represents the disk partition in SDA and assign them in sda1, sda2, and sda3 formats.
If you want to check the information for a specific block device, then specify its mount path (let’s say “/dev/sda“) as an argument to this command.
$ lsblk /dev/sda
Now, let’s see a few commonly used options with the lsblk command.
lsblk Command Options:
The lsblk command offers various options that can be used to add or remove columns from the output, print extra information about specific devices, hide the header, and much more.
Limited Columns in the Output
Using the “
-o” flag, you can manipulate the columns in the output by specifying each column with its name using a comma as a separator.
$ lsblk -o NAME,SIZE,MOUNTPOINT
The following is a list of column names supported by this option.
NAME– device name
PATH– path to the device node
MAJ:MIN– major:minor device number
FSAVAIL– filesystem size available
FSSIZE– filesystem size
FSTYPE– filesystem type
FSUSED– filesystem size used
FSUSE%– filesystem use percentage
FSROOTS– mounted filesystem roots
MOUNTPOINT– where the device is mounted
LABEL– filesystem LABEL
UUID– filesystem UUID
PTTYPE– partition table type
PARTLABEL– partition LABEL
PARTUUID– partition UUID
Check the complete list using the “
lsblk -h” command.
List Empty Block Devices
A block device with zero size is skipped in the output and can be included using the “
$ lsblk -a
Print the Size Column in Bytes
The default format used to mention the block device size is in human-readable format, i.e., in K, M, G, T, etc. However, you can use the “
-b” flag to print the size in bytes rather than in a human-readable format.
$ lsblk -b
Print the Output in List Format
By default, the command output will be in tree-like format, which can be changed to list format using the “
$ lsblk -l
Print the Output without a Header
-n” flag will remove the header from the columns while showing the output.
$ lsblk -n
Display Only the SCSI Devices
-S” flag will only print the information about the SCSI devices, which are mostly your hard disk or CD/DVD.
$ lsblk -S
Bonus Tip! Print All the Partitions and their UUID
Linux offers another command-line utility, blkid, that can be used to list all the recognized partitions and their Universally Unique Identifier (UUID).
Here comes the end of this article.
If you have any questions or queries related to this topic, then feel free to ask them in the comment section.
Till then, peace!