How to use the lsblk and the blkid commands on Linux

How To Use The Lsblk And The Blkid Commands On Linux

In this article we will be discussing the lsblk (pronounced “L-S-block”) command. In simple language, the lsblk command is used to list out and give information about all of the “block” devices in our system. Now, what are “block” devices you ask? To know that read on!

Block Devices: What are they?

Block devices are mass storage devices whose contents can be accessed in any order. Unlike character devices, block devices allow us to read or write a block(usually 512 bytes at a time) of any size and any alignment. These devices support random access to the user. The most common example of a block device is the Hard disk. The CD-Drive and USB Drives that you carry around are also good examples.

Command Syntax and options

The basic syntax of the lsblk command is as follows:

lsblk [option] [<device>]

The basic command is simply lsblk, which will list out the block devices in a pretty tree format as can be seen in the following picture:

Running the lsblk command without any flags
Running the lsblk command without any flags

The next option to learn is that the columns can be manipulated, you can list out the columns you want as options to the main command:

lsblk -o NAME,RM

Using the o flag you can specify which columns you want to see, keep in mind this might not give you the output in the tree format. In the above example, we simply listed out all devices with the name and their removable property of it, where 0 stands for success and 1 for failure.

Running lsblk with the -o flag
Running lsblk with the -o flag

The most important ones from the list of available flags are given below, remember to keep them comma-separated (without any space in between).

Available output columns:
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
PARTUUID  partition UUID

For the full list run the below command:

lsblk --help

You might notice that when we ran the lsblk command without any flags, the command showed various snaps as an output, but say we don’t want that, then we simply have to run the lsblk command with a grep pipe. See the below code:

lsblk | grep -v "loop"
Removing the snap packages from output
Removing the snap packages from output

So, the lsblk command provides useful and easy-to-understand information about your block devices.

The blkid command

The blkid command is used to identify the attributes of block devices in your system. When run without any flags the output is as follows:

Running the blkd command
Running the blkd command

Once executed the user can see partitions, labels, and the 128-bit unique identifiers (UUIDs). And can also see the types of the file-systems.

From playing with the different settings we have found the most efficient way to quickly get some info, which would be to run the following command:

lsblk --fs | grep -v loop
Running the lsblk command with the --fs flag
Running the lsblk command with the –fs flag


So there you go guys, you now know what block devices are and how to see what resources they are using, what are their file-system types and every info about them. Hope you guys liked this article and as always, thanks for reading!