lsblk - Linux
Overview
The lsblk
command in Linux lists information about all available or the specified block devices. It reads the sysfs
filesystem to gather information, displaying a tree of devices, which includes disk partitions and storage details. It is commonly used to view the layout of block devices, their mount points, and their logical volume management (LVM) configurations. lsblk
is particularly handy for system administrators and users who need to manage disks or troubleshoot disk issues.
Syntax
The general syntax of the lsblk
command is:
lsblk [options] [devices]
Here, [options]
represent different flags that can be used to modify the command’s behavior, and [devices]
specifies particular block devices whose information is to be displayed.
Options/Flags
-a, --all
: Also list empty devices and devices without partitions.-b, --bytes
: Print the SIZE column in bytes rather than in a human-readable format.-d, --nodeps
: List only disk devices without their partitions.-e, --exclude list
: Exclude devices by major device number.-f, --fs
: Output filesystem-related information, including type, size, and mount point.-i, --ascii
: Use ASCII characters for tree formatting instead of Unicode.-J, --json
: Output the device list in JSON format.-l, --list
: Use the list output format instead of the tree view.-m, --perms
: Output permissions on the device, owner, and group.-n, --noheadings
: Do not print headings.-o, --output list
: Customize the columns displayed.-p, --paths
: Print complete device path.-s, --scsi
: Output SCSI devices only.-S, --inverse
: Invert the dependencies in the tree.
Examples
-
Basic Usage:
List all block devices with default settings:lsblk
-
Display Filesystem Information:
To display information about filesystems:lsblk -f
-
View in JSON Format:
Display hardware information in JSON format for scripting:lsblk -J
-
Customizing Output:
Display only the device name, label, and mount point:lsblk -o NAME,LABEL,MOUNTPOINT
Common Issues
- Missing Devices: Some devices might not appear if they are handled by drivers not supporting the standard sysfs interface. Make sure all drivers are properly installed.
- Output Clutter: In systems with many devices, the default tree view can be overwhelming. Consider using the
-l
option for a list format or filtering the output with-o
.
Integration
Combine lsblk
with grep
to filter for specific devices, or use in scripts to dynamically find devices:
# Find a device with specific mount point
lsblk | grep '/my/mount/point'
# Use in a script to check if a USB drive is mounted
if lsblk -o MOUNTPOINT | grep -qs '/media/usb'; then
echo "USB drive is mounted."
else
echo "USB drive is not mounted."
fi
Related Commands
fdisk
: Used for disk partitioning.blkid
: Locate/print block device attributes.mount
: Mount a filesystem.umount
: Unmount a filesystem.
For more detailed insights, refer to the official lsblk
man page (man lsblk
) or the Linux documentation available online at portals like the Linux Kernel Archives or your distribution’s official resources.