lsblk: Listing Block Devices
lsblk (list block devices) is a command-line utility used to list information about all available block devices (like hard drives, SSDs, USB drives, and their partitions) on your Linux system. It presents the information in a tree-like format, making it easy to understand the relationships between different devices and their partitions. It’s an essential tool for system administrators and users managing storage.
1. Basic lsblk Output
Without any options, lsblk provides a concise overview of your block devices, including their name, major/minor numbers, size, and mount points.
lsblkExample Output:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 100G 0 disk
├─sda1 8:1 0 500M 0 part /boot
└─sda2 8:2 0 99.5G 0 part
├─vg0-root 254:0 0 50G 0 lvm /
└─vg0-swap 254:1 0 49.5G 0 lvm [SWAP]
sdb 8:16 0 200G 0 disk
└─sdb1 8:17 0 200G 0 part /data
2. Displaying Specific Columns (with Labels)
You can customize the output of lsblk to show only the information relevant to you using the -o (output) option, followed by a comma-separated list of column names.
lsblk -o NAME,FSTYPE,SIZE,MOUNTPOINT,LABELOptions Explained:
-o NAME,FSTYPE,SIZE,MOUNTPOINT,LABEL: Specifies the columns to display.NAME: Device name (e.g.,sda,sdb1).FSTYPE: File system type (e.g.,ext4,xfs,swap).SIZE: Size of the block device.MOUNTPOINT: Where the device is mounted in the file system tree.LABEL: File system label (if set).
3. Other Useful lsblk Options
Include Empty Devices (-a)
By default, lsblk does not list empty devices (e.g., CD/DVD drives with no disc). Use -a to include them.
lsblk -aDisplay Device Owners and Permissions (-m)
Show device owner, group, and mode (permissions).
lsblk -mOutput in JSON Format (-J)
For scripting or programmatic consumption, JSON output is very useful.
lsblk -JDisplay Only Specific Device Types (-t)
Filter the output to show only specific types of block devices (e.g., disk, part, lvm).
lsblk -t -o NAME,TYPE,SIZE,MODEL-t: Topology information (can be combined with-oto addTYPE).
Human-Readable Sizes (-h)
Display sizes in human-readable format (e.g., 1G, 500M).
lsblk -hThis is often combined with other options for clearer output.