YouTip LogoYouTip

Linux Comm Lsblk

[![Image 1: Linux Command Reference](#) Linux Command Reference](#) * * * ## 1. Basic Concepts `lsblk` is a practical command in Linux systems used to list information about all available block devices. Block devices are storage devices that read and write data in blocks, such as hard drives, SSDs, USB drives, etc. ### 1.1 Command Name Meaning * `ls`: Abbreviation for "list", meaning to display * `blk`: Abbreviation for "block", meaning block device * Combined, it means "list block devices" ### 1.2 Main Functions * Display a tree structure of all block devices * Show basic device information (name, size, type, etc.) * Display device partition information * Show device mount point information * * * ## 2. Command Syntax lsblk [device...] ### 2.1 Parameter Description * If no parameters are specified, `lsblk` 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 devices themselves, not partitions | | `-e` | Exclude devices with specified major device numbers | | `-f` | Display file system information | | `-i` | Use ASCII characters to display tree structure | | `-J` | Output in JSON format | | `-l` | Use list format output (non-tree) | | `-m` | Display device owner information and permissions | | `-n` | Do not display header row | | `-o` | Specify columns to display | | `-P` | Output in key-value pair format | | `-r` | Use raw format output | | `-S` | Display only SCSI devices | | `-t` | Display device topology information | | `-x` | Sort by specified column | * * * ## 3. Output Field Description By default, the `lsblk` command displays the following columns: | Column Name | Description | | --- | --- | | NAME | Device name | | MAJ:MIN | Major and minor device numbers | | RM | Whether it's a removable device (1 for yes, 0 for no) | | SIZE | Device size | | RO | Whether it's 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 Sample 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 sr0 11:0 1 1024M 0 rom ### 4.2 Display File System Information ## Example lsblk -f Sample 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 ### 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 (Not Partitions) ## Example lsblk -d ### 4.7 Output in JSON Format ## Example lsblk -J * * * ## 5. Practical Application Scenarios ### 5.1 Viewing Newly Inserted USB Drives or External Hard Drives ## Example # Execute before inserting USB drive lsblk > before.txt # Execute after inserting USB drive lsblk > after.txt # Compare differences diff before.txt after.txt ### 5.2 Finding Unmounted Partitions ## Example lsblk -f|grep-v"MOUNTPOINT"|grep-v"FSTYPE" ### 5.3 Viewing Device Physical Topology ## Example lsblk -t ### 5.4 Monitoring Device Changes ## Example watch-n 1 lsblk * * * ## 6. FAQ ### 6.1 What is the difference between lsblk and df commands? * `lsblk` displays block devices and their partition structure * `df` displays disk space usage for mounted file systems * `lsblk` is better for viewing device physical structure, while `df` is better for viewing disk space usage ### 6.2 Why do some devices not display size? These devices may not have a valid partition table or may not be recognized by the system. 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 system administrators and users. It provides an intuitive tree view to display block devices and their partition relationships. Through different option combinations, you can obtain various detailed device information, which is very useful for disk management, troubleshooting, and system maintenance. Remember common options: * `-f` View file system information * `-o` Customize output columns * `-J` Get JSON format output * `-m` View permission information Mastering the `lsblk` command allows you to manage storage devices in Linux systems more efficiently. [![Image 2: Linux Command Reference](#) Linux Command Reference](#)
← Linux Comm PartedLinux Comm Basename β†’