
lsblk: Inspect Block Devices Efficiently
lsblk: Inspect Block Devices Efficiently
A lightweight tool to list information about block devices in a tree-like view. It works well for quick audits of disks, partitions, and filesystems without needing to parse /proc or /sys manually.
Quick start
- Basic usage (tree view of all devices):
lsblk
- Include empty devices (no partitions) in the output:
lsblk -a
- Show data in bytes instead of human-friendly units:
lsblk -b
- Show filesystem information alongside devices:
lsblk -f
- Use ASCII characters for the tree (no unicode):
lsblk -i
- Display a topology view (how devices connect to each other):
lsblk -t
Tip: Combine options to tailor output for scripts or reports. For example, a clean, ASCII tree with filesystem info:
lsblk -aif
Common options you’ll love
- -a, —all: Include empty devices in the listing.
- -b, —bytes: Display SIZE in bytes rather than human-readable units.
- -f, —fs: Print filesystem information (FSTYPE, LABEL, UUID, MOUNTPOINT).
- -i, —ascii: Use ASCII characters for the tree format.
- -t, —topology: Show device topology information (RING, SLOTS, etc.).
- -e, —exclude: Exclude specified major device numbers (comma-separated).
- -o, —output: Choose exactly which columns to print.
Example: show a custom set of columns
lsblk -o NAME,SERIAL,MODEL,TRAN,TYPE,SIZE,FSTYPE,MOUNTPOINT
Practical examples
- List all devices with a focus on the mount points and filesystem type:
lsblk -o NAME,SIZE,FSTYPE,MOUNTPOINT
- Exclude common non-storage devices (e.g., RAM disks) by major number:
lsblk -e 1,7
- Print SIZE in bytes for scripting precision:
lsblk -b
- Display a filesystem-aware view including mount points:
lsblk -f
# Note: when running with sudo vs. non-sudo
# lsblk generally works without root, but some values may be limited by permissions.
Common pitfalls
- Misreading the SIZE column after switching between -h (human-readable) and -b (bytes). If your script expects fixed bytes, always use -b.
- Relying on the default order. lsblk prints in a structured tree, but the ordering may not match your expectations for large arrays; specify -o to fix the columns you care about.
- Forgetting that -a includes empty devices. This can dramatically increase output on systems with many virtual devices.
When to prefer lsblk over other tools
- For a clean, script-friendly snapshot of disks and partitions without parsing /proc/partitions.
- When you need a quick topology view to understand how devices are connected (SATA, NVMe, loop devices).
- When you want to tailor the output to a report by selecting exact columns with -o.
Quick tips for scripting
- Always pin the columns you need with -o to ensure consistent output parsing.
- Combine -f with -o to quickly capture filesystem details in logs.
- Use -a cautiously in automation to avoid flood of unnecessary entries.
TL;DR
- lsblk lists block devices in a readable, tree-like format.
- Use -a to include empty devices, -f for filesystem info, -t for topology, -b for bytes, -i for ASCII, and -o to tailor columns.
- Example: lsblk -o NAME,SERIAL,MODEL,TRAN,TYPE,SIZE,FSTYPE,MOUNTPOINT