lsblk Command Examples in Linux (2024)

If you notice, most Linux commands explain their purpose by their names. Same goes for the lsblk which stands for list block devices.

"List block devices" simply means it will list storage devices.

While the lsblk is one of the most basic Linux commands, it plays crucial role when troubleshooting a storage drive.

So in this tutorial, I will walk you through how you can use the lsblk command with practical examples.

How to use the lsblk command in Linux

To use the lsblk command to its full potential, you are required to know its syntax. This is the reason why I'll start this tutorial by sharing the syntax first:

lsblk [options] [device(s)]

Here,

  • [options]: it is used to fine-tune the default behavior of the lsblk command. For example, you use the -a option to list all the block devices.
  • [devices(s)]: here's where you list more block devices to get specific information about it.

Now, let's take a look at some common options used with the lsblk command:

OptionDescription
-aList all block devices, including empty devices and cdroms.
-fDisplay filesystem information for each device.
-mPrint permissions for each device.
-MPrint kernel device-mapper mappings.
-oSpecify fields to display in the output.
-tPrint topology information for each device.
-xSort output by specified fields.

Practical examples of the lsblk command

In this section, I will walk you through some practical examples of the lsblk command so you can learn more about the command and get a better idea of how to use it.

1. List all the block devices

To list all the block devices, use the -a flag with the lsblk command as shown here:

lsblk -a
lsblk Command Examples in Linux (1)

Here,

  • NAME: it shows the name of the block device.
  • MAJ:MIN: it shows the major and minor device numbers used by the kernel to identify the device.
  • RM: it tells you if the listed device is removable or not. 1 means removable and 0 means non-removable.
  • SIZE: displays the size of the storage block device.
  • RO: tells you that if the device is read-only or not. 1 indicates the device is read-only whereas 0 means the device can read and write.
  • TYPE: it indicates the type of device drive. For reference, disk means the entire disk, part is for partition of the disk, rom for CD-ROM, and lvm for the logical volume.
  • MOUNTPOINTS: shows the mount point where the device is mounted.

2. Display filesystem information

This is my favorite one. When you use the -f flag with the lsblk command, it prints detailed information about each device block:

lsblk -f
lsblk Command Examples in Linux (2)

3. Get information about a specific disk drive

To get information about a specific disk drive, all you have to do is append the path to the disk drive as shown here:

lsblk /path/to/drive

For example, if I want to get details of the sda drive, then I'll be using the following:

lsblk /dev/sda
lsblk Command Examples in Linux (3)

4. Print specific details only

There are times when you only want to print specific details while using the lsblk command and for that purpose, you use the -o flag and specify what details to print:

lsblk -o <data_filed(s)>

For example, if I want to print only NAME, SIZE, TRAN, and REV so I'll be using the following:

lsblk -o NAME,SIZE,TRAN,REV
lsblk Command Examples in Linux (4)

5. Get information of the device owner, group, and mode

If you want to print information such as device owner, group, and mode, then all you need to do is use the -m flag with the lsblk command:

lsblk -m
lsblk Command Examples in Linux (5)

6. Exclude dependent device blocks

Whenever you use the lsblk, it will print the name of the dependent blocks such as sda1 is dependent on sda and sdb2 is dependent on sdb.

So what if you only want to print independent drives such as sda and sdb? Well, that's pretty simple and can be done using the -d flag:

lsblk -d
lsblk Command Examples in Linux (6)

Wrapping Up...

This was a quick tutorial on how you can use the lsblk command on Linux where I went through some practical examples of it.

Sure, you can get more out of it by reading the man page of the lsblk command. Don't know how to use the man pages yet? Here's a detailed guide on using man pages:

Understanding the man pages in LinuxThough extremely useful, man pages in Linux can be daunting and intimidating at first. This article aims to make it a bit easier to peruse manuals and quickly get the help one needs.Linux HandbookLHB Community

I hope you will find this guide helpful.

lsblk Command Examples in Linux (2024)

References

Top Articles
Latest Posts
Article information

Author: Maia Crooks Jr

Last Updated:

Views: 5835

Rating: 4.2 / 5 (63 voted)

Reviews: 94% of readers found this page helpful

Author information

Name: Maia Crooks Jr

Birthday: 1997-09-21

Address: 93119 Joseph Street, Peggyfurt, NC 11582

Phone: +2983088926881

Job: Principal Design Liaison

Hobby: Web surfing, Skiing, role-playing games, Sketching, Polo, Sewing, Genealogy

Introduction: My name is Maia Crooks Jr, I am a homely, joyous, shiny, successful, hilarious, thoughtful, joyous person who loves writing and wants to share my knowledge and understanding with you.