Linux lsblk Command

Linux 命令大全Linux Command Reference


1. Basic Concepts

lsblklsblk is a practical command in Linux systems, used to list information about all available block devices in the system. Block devices are storage devices that read and write data in blocks, such as hard drives, SSDs, USB drives, etc.

1.1 Meaning of the Command Name

  • ls: Abbreviation of list, meaning to list
  • blk: Abbreviation of block, meaning block device
  • Combined together, it means "list block devices".

1.2 Main Functions

  • Display the tree structure of all block devices
  • Show basic device information (name, size, type, etc.)
  • Display the partition status of devices
  • Show device mount point information

2. Command Syntax

lsblk [选项] [设备...]

2.1 Parameter Description

  • If no parameters are specified,lsblklsblk will list all block devices
  • You can specify one or more device names as parameters to display only information for those devices.

2.2 Common Options

Option Description
-a Display all devices (including empty devices)
-b Display device size in bytes
-d Display only the device itself, not partitions
-e Exclude devices with the specified major device number
-f Display file system information
-i Use ASCII characters to display the tree structure
-J Output in JSON format
-l Output in list format (not tree)
-m Display device owner information and permissions
-n Do not display the header line
-o Specify the columns to display
-P Output in key-value pair format
-r Output in raw format
-S Display only SCSI devices
-t Display device topology information
-x Sort by the specified column

3. Output Field Description

By default,lsblkthe lsblk command displays the following columns:

Column Name Description
NAME Device name
MAJ:MIN Major device number and minor device number
RM Whether it is a removable device (1 means yes, 0 means no)
SIZE Device size
RO Whether it is a read-only device (1 means yes, 0 means no)
TYPE Device type (disk, part, rom, etc.)
MOUNTPOINT Device mount point

4. Practical Examples

4.1 Basic Usage: List All Block Devices

Example

lsblk

Example output:

NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0 238.5G  0 disk 
├─sda1   8:1    0   512M  0 part /boot/efi
├─sda2   8:2    0   732M  0 part /boot
└─sda3   8:3    0 237.3G  0 part 
  └─sda3_crypt
        253:0    0 237.3G  0 crypt 
          ├─vgubuntu-root
          │    253:1    0 236.3G  0 lvm  /
          └─vgubuntu-swap_1
               253:2    0   976M  0 lvm  [SWAP]
sr0     11:0    1  1024M  0 rom  

4.2 Display File System Information

Example

lsblk -f

Example output:

NAME   FSTYPE   LABEL UUID                                 MOUNTPOINT
sda                                                         
├─sda1 vfat           67E3-17ED                            /boot/efi
├─sda2 ext4           5b3e5a5e-2a9d-4a3e-9b1e-1e1e1e1e1e1e /boot
└─sda3 crypto_LUKS    6c3e5a5e-3a9d-5b3e-9b1e-2e2e2e2e2e2e 
  └─sda3_crypt LVM2_member
          ├─vgubuntu-root
          │    ext4           7d3e5a5e-4a9d-6c3e-9b1e-3e3e3e3e3e3e /
          └─vgubuntu-swap_1
               swap           8e3e5a5e-5a9d-7d3e-9b1e-4e4e4e4e4e4e [SWAP]

4.3 Customize Output Columns

Example

lsblk -o NAME,SIZE,TYPE,MOUNTPOINT,FSTYPE

4.4 Display in List Format

Example

lsblk -l

4.5 Display Device Owner Information

Example

lsblk -m

4.6 Display Only Disk Devices (Without Partitions)

Example

lsblk -d

4.7 Output in JSON Format

Example

lsblk -J

5. Practical Application Scenarios

5.1 View Newly Inserted USB Drive or External Hard Disk

Example

# Run this before inserting the USB drive
lsblk > before.txt

# Run this after inserting the USB drive
lsblk > after.txt

# Compare the differences
diff before.txt after.txt

5.2 Find Unmounted Partitions

Example

lsblk -f | grep -v "MOUNTPOINT" | grep -v "FSTYPE"

5.3 View Device Physical Topology

Example

lsblk -t

5.4 Monitor Device Changes

Example

watch -n 1 lsblk

6. FAQ

6.1 What is the difference between lsblk and df commands?

  • lsblklsblk displays block devices and their partition structure.
  • dfdf displays the disk space usage of mounted file systems.
  • lsblklsblk is more suitable for viewing the physical structure of devices,dfdf is more suitable for viewing disk space usage.

6.2 Why do some devices not show a size?

It may be because these devices do not have a valid partition table or are not recognized by the system. You can try using the-aoption to view all devices.

6.3 How to display only specific types of devices?

Example

# Display only disks
lsblk -d -o NAME,RO,TYPE,SIZE,MOUNTPOINT | grep disk

# Display only partitions
lsblk -o NAME,RO,TYPE,SIZE,MOUNTPOINT | grep part

7. Summary

lsblklsblk is an essential disk management tool for Linux system administrators and users. It provides an intuitive tree view to display block devices and their partition relationships. Through different combinations of options, you can obtain various detailed device information, which is very useful for disk management, troubleshooting, and system maintenance.

Remember common options:

  • -fView file system information
  • -oCustomize output columns
  • -JGet JSON format output
  • -mView permission information

Masteringlsblkthe lsblk command can help you manage storage devices in Linux systems more efficiently.

Linux 命令大全Linux Command Reference

Other Extensions