List block device information
lsblk command is used to list information about all available block devices and also displays the dependencies between them, but it does not list RAM disk information. Block devices include hard drives, flash drives, cd-ROMs, etc. The lsblk command is included in the util-linux-ng package, which is now renamed util-linux. This package comes with several other tools, such as dmesg. To install lsblk, download the util-linux package here. Fedora users can install this package through the command sudo yum install util-linux-ng
.
-a, --all # Display all devices.
-b, --bytes # Display device size in bytes.
-d, --nodeps # Do not display slaves or holders.
-D, --discard # print discard capabilities.
-e, --exclude <list> # Exclude devices (default: RAM disks).
-f, --fs # Display file system information.
-h, --help # Display help information.
-i, --ascii # use ascii characters only.
-m, --perms # Display permission information.
-l, --list # Use list format to display.
-n, --noheadings # Do not display headings.
-o, --output <list> # Output column.
-P, --pairs # Use key="value" format to display.
-r, --raw # Use raw format display.
-t, --topology # Display topology information.
The lsblk command will list all block devices in a tree view by default. Open a terminal and enter the following command:
lsblk
NAME MAJ:MIN rm SIZE RO type mountpoint
sda 8:0 0 232.9G 0 disk
├─sda1 8:1 0 46.6G 0 part /
├─sda2 8:2 0 1K 0 part
├─sda5 8:5 0 190M 0 part /boot
├─sda6 8:6 0 3.7G 0 part [SWAP]
├─sda7 8:7 0 93.1G 0 part /data
└─sda8 8:8 0 89.2G 0 part /personal
sr0 11:0 1 1024M 0 rom
The names of the 7 columns are as follows:
The default option does not list all empty devices. To view these empty devices, use the following command:
lsblk -a
The lsblk command can also be used to list ownership of a specific device, as well as groups and modes. This information can be obtained with the following command:
lsblk -m
This command can also obtain only the information of the specified device. This is accomplished by specifying the device name after the options provided to the lsblk command. For example, you might be interested in knowing the size of your disk drive in bytes. You can do this by running the following command:
lsblk -b /dev/sda
Equivalent to
lsblk --bytes /dev/sda
You can also combine several options to get specific output. For example, you might want to list devices in a list format instead of the default tree format. You may also be interested in removing headers for different column names. Two different options can be combined to get the desired output with the following command:
lsblk-nl
To get a list of SCSI devices, you can only use the -S option. This option is a capital S and should not be confused with the -s option, which prints dependencies in reverse order.
lsblk -S
lsblk lists SCSI devices, and -s is the reverse order option (reversing the organizational relationship of devices and partitions), which will give the following output. input the command:
lsblk -s