Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Linux lsblk Command

Linux lsblk Command

Linux Command Reference Linux Command Reference


1. Basic Concepts

lsblk is a utility command in Linux used to list information about all available block devices in the system. A block device is a storage device that reads and writes data in blocks, such as hard disks, SSDs, and USB drives.

1.1 Meaning of the Command Name

1.2 Main Functions


2. Command Syntax



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

2.1 Parameter Description

2.2 Common Options

Option Description
-a Display all devices (including empty devices)
-b Display device sizes in bytes
-d Display only the devices themselves, not partitions
-e Exclude devices with a 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 (non-tree)
-m Display device owner information and permissions
-n Do not display the header row
-o Specify the columns to display
-P Output in key-value format
-r Output in raw format
-S Display only SCSI devices
-t Display device topology information
-x Sort by a specified column

3. Output Field Description

By default,lsblk The command displays the following columns:

Column Name Description
NAME Device name
MAJ:MIN Major and minor device numbers
RM Whether it is a removable device (1 for yes, 0 for no)
SIZE Device size
RO Whether it is a read-only device (1 for yes, 0 for 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 (No Partitions)

Example

lsblk

-d

4.7 Output in JSON Format

Example

lsblk

-J


5. Practical Application Scenarios

5.1 View a 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 differences

diff

before.txt after.txt

5.2 Find Unmounted Partitions

Example

lsblk

-f

|

grep

-v

"MOUNTPOINT"

|

grep

-v

"FSTYPE"

5.3 View the Physical Topology of Devices

Example

lsblk

-t

5.4 Monitor Device Changes

Example

watch

-n

1

lsblk


6. Frequently Asked Questions

6.1 What Is the Difference Between the lsblk and df Commands?

6.2 Why Do Some Devices Show No Size?

These devices may not have a valid partition table or may not be recognized by the system. You can try using the -a option 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

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

Remember the common options:

Mastering the lsblk command can help you manage storage devices in Linux more efficiently.

Linux Command Reference Linux Command Reference