A Block device is a file referring to a device. The devices can be HDDs, SDD's, RAM Disks, etc. The block device files can be found under the directory /dev.
In this tutorial, we learn about lsblk command in Linux to list block devices.
lsblk command is used to list information about all available block devices in Linux. lsblk is preinstalled in most Linux Distributions. It comes under the utils-linux package.
Lsblk is normally used to find devices and partitions information. The blkid command can give information such as filesystem and UUID. Whereas df command is used mostly for disk usage and filesystem information.
The simplest form to use lsblk is without any arguments, which will display a list of block devices in a tree format.
lsblk command output with seven columns such as NAME, MAJ:MIN, RM, SIZE, RO, TYPE, and MOUNTPOINT. Each column is explained:
NAME - This is the device name.
MAJ:MIN - This column shows the major and minor device number.
RM - This column shows whether the device is removable or not. Note in this example the device sdb and sr0 have their RM values equals to 1 indicating they are removable.
SIZE - This is column gives information on the size of the device.
RO - This indicates whether a device is read-only. In this case, all devices have a RO=0 indicating they are not read-only.
TYPE - This column shows the block device is a disk or a partition(part) within a disk. In the picture, sda is the disk while sr0 is a read-only memory (rom).
MOUNTPOINT: This column indicates the mount point on which the device is mounted.
Let's check how to use lsblk command:
01. To list all block devices
Use the option -a to display all devices including empty devices:
$ lsblk -a
02. To change the default lsblk output in tree-like format, use -l option
$ lsblk -l
03. Show specific device
Use lsblk following the device name to display information about a specific device.
$ lsblk /dev/sda5
04. Display only selective columns
If you want you can display the output of specific columns use the -o option.
For example to list name and size columns type:
$ lsblk -o name,size
05. Display device permissions
You can use lsblk to print each device ownership and permissions using -m option.
$ lsblk -m
06. To Display only SCSI devices use -S option.
$ lsblk -S
07. Display output in ASCII character format.
The default tree format is not user friendly and you can use -i option to display in ASCII format:
$ lsblk -i
08. To display the zone model of each device use -z option.
$ lsblk -z
In this tutorial, we learned how to use lsblk command in Linux to find information about connected block devices. Thanks for reading, please provide your suggestion in the comment section.