lsblk ‐ #storage #disks #troubleshooting - five4nets/Linux-Knowledgebase GitHub Wiki

🔍 Linux lsblk Command Tutorial

The lsblk (list block devices) command is a powerful utility in Linux used to display information about block devices such as hard drives, SSDs, USB drives, and their partitions. It’s especially useful for system administrators and anyone managing storage devices.


🧰 Basic Syntax

lsblk [OPTIONS] [DEVICE...]
  • DEVICE: Optional. Specify a device like /dev/sda to limit output.
  • OPTIONS: Flags to customize the output.

📦 Installation

lsblk is part of the util-linux package, which is pre-installed on most Linux distributions. If needed:

Debian/Ubuntu:

sudo apt install util-linux

Red Hat/CentOS/Fedora:

sudo dnf install util-linux

🔧 Common Options

Option Description
-a Show all devices, including empty ones
-b Show sizes in bytes
-d Show only top-level devices (no partitions)
-f Show filesystem info (LABEL, UUID, etc.)
-m Show device owner, group, and permissions
-o Customize output columns
-t Display devices in a tree-like format
-n Suppress column headers
-J Output in JSON format
-x Sort output by specified column

🧪 Examples

1. List All Block Devices

lsblk

2. Include Empty Devices

lsblk -a

3. Show Filesystem Info

lsblk -f

4. Show Only Top-Level Devices

lsblk -d

5. Display in Tree Format

lsblk -t

6. Show Device Permissions

lsblk -m

7. Customize Output Columns

lsblk -o NAME,SIZE,TYPE,MOUNTPOINT

8. Show Info for a Specific Device

lsblk /dev/sda

9. Output in JSON Format

lsblk -J

🧠 Tips

  • Combine with grep to filter output:
    lsblk | grep sda
    
  • Use lsblk -f before mounting a device to check its filesystem and label.
  • Use lsblk -o +UUID to include UUIDs in the output.

📚 References


Happy device exploring! 🧭


Let me know if you'd like a version that includes visual diagrams or integrates with `udevadm` for deeper device insights!