Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Shell Scripting
  • Kali Linux
  • Ubuntu
  • Red Hat
  • CentOS
  • Docker in Linux
  • Kubernetes in Linux
  • Linux interview question
  • Python
  • R
  • Java
  • C
  • C++
  • JavaScript
  • DSA
Open In App
Next Article:
How to List All Block Devices in Linux | lsblk Command
Next article icon

How to List All Block Devices in Linux | lsblk Command

Last Updated : 15 Sep, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

Understanding the storage devices connected to your Linux system is crucial for efficient system management. The 'lsblk' command, short for "list block devices," is a powerful tool that provides detailed information about block devices such as hard drives, solid-state drives, and other storage-related devices.

Here, we will look into the 'lsblk' command, exploring its syntax, options, and practical implementations.

Table of Content

  • Installing lsblk Command in Linux
  • Syntax of lsblk Command in Linux
  • Options Available in lsblk Command
  • Practical Example of lsblk Command in Linux
  • How to List All Block Devices in Linux
  • How to Display All Devices, Including Empty Ones
  • How to Print sizes in bytes instead of the more human-readable formats
  • How to Viewing Devices in a Tree-Like Format
  • To print zone model for devices.  
  • To skip slave entries
  • How to Invert the output, showing only non-empty devices
  • To print information about device owner, group, and mode of block devices.  
  • How to Define the output columns to display
  • To hide column headings
  • To display help section of the command

What is the 'lsblk' Command?

'lsblk' is used to display details about block devices and these block devices(Except ram disk) are basically those files that represent devices connected to the pc. It queries '/sys' virtual file system and 'udev db' to obtain information that it displays. And it basically displays output in a tree-like structure. This command is part of the util-Linux package, which comes pre-installed on many Linux distributions, providing users with essential system management utilities.

Installing lsblk Command in Linux

Many Linux distributions do not have lsblk command pre-installed. To install it use the following commands as per your Linux distribution. 

1. In case of Debian/Ubuntu  

sudo apt-get install util-linux

2. In case of CentOS/RedHat  

sudo yum install util-linux-ng

3. In case of Fedora OS  

sudo yum install util-linux-ng

Syntax of lsblk Command in Linux

The basic syntax of the lsblk command is simple:

lsblk [OPTIONS] [DEVICE...]

Here,

  • [OPTIONS] represents the various flags and parameters that can be used with the command.
  • [DEVICE...] refers to the specific block devices you want to list. If no device is specified, lsblk will display information for all available block devices.

Options Available in lsblk Command

Options

Description

-a or --all

Display all devices, including empty ones.

-b or --bytes

Print sizes in bytes instead of the more human-readable formats.

-i or --inverse

Invert the output, showing only non-empty devices.

-l or --list

Print output in a list format.

-o or --output

Define the output columns to display.

-p or --pairs

Display key-value pairs for each device.

-t or --tree

Print devices in a tree-like format.

-x or --exclud

Exclude devices that match the specified criteria.

Practical Example of lsblk Command in Linux

1. How to List All Block Devices in Linux

To display block devices. 

lsblk 

This command will display a hierarchical view of all block devices connected to your system, including information about partitions and mount points.

to-display-block-devices

2. How to Display All Devices, Including Empty Ones

To display empty block devices as well.  

lsblk -a 

This command includes all devices, even empty ones, in the output. It can be useful when you want to see all available devices, including those without any partitions or mount points.

to-display-empty-block-devices

3. How to Print sizes in bytes instead of the more human-readable formats

To print size information in bytes. 

lsblk -b

The '-b' option displays sizes in bytes. This can be handy when you need precise size information for block devices.

display-block-devices-in-bytes

4. How to Viewing Devices in a Tree-Like Format

The '-t' option organizes devices in a tree-like format, making it easier to visualize the relationships between devices and partitions.

lsblk -t
viewing devices in tree-like format
viewing devices in tree-like format


5. To print zone model for devices.  

lsblk -z 
print-zone-model-block-devices

6. To skip slave entries

lsblk -d 

This will skip all the slave entries. 

to-avoid-slaves

7. How to Invert the output, showing only non-empty devices

To use ASCII characters for tree formatting.  

lsblk -i 

Inverting the output with '-i' will show only non-empty devices. This is useful when you want to focus on devices with existing partitions or mount points.

block-devices-ASCII-tree-formatting

8. To print information about device owner, group, and mode of block devices.  

This will display all details of device owner, group and mode of block devices. 

lsblk -m  
to-display-mode-owner-group-block-device

9. How to Define the output columns to display

To print selected columns of block-devices. 

lsblk -o SIZE, NAME, MOUNTPOINT 

Use '-o' to customize the output columns. In this example, we specify that we only want to see the device name, size, and mount point for each device.

to-display-specific-columns

This will print only the specified columns. 

10. To hide column headings

This will hide column headings. 

lsblk -dn 
hide-column-heading-block-devices

11. To display help section of the command

lsblk --help  

This will display the help section of the command.

Conclusion

In this article we discussed the 'lsblk' command which is a vital tool for managing storage devices in Linux, offering detailed insights into hard drives and SSDs. This article covers its syntax, options, and practical applications. 'lsblk', part of the util-Linux package, efficiently queries system files to present a tree-like view of block devices. Examples demonstrate how to list devices, customize output, and visualize storage efficiently. Mastering 'lsblk' enhances system administration, allowing users to navigate and manage storage resources effectively.


    Next Article
    How to List All Block Devices in Linux | lsblk Command

    M

    manav014
    Improve
    Article Tags :
    • Technical Scripter
    • Linux-Unix
    • linux-command
    • Linux-system-commands

    Similar Reads

      iptables-save command in Linux with examples
      The information transfer from a remote computer to your local computer and the vice-versa are viewed as the transfer of data packets by the firewall. The firewall has the control of data packets that are both incoming and outgoing.iptables is a utility to create a rule-based firewall that is pre-ins
      3 min read
      iwconfig command in Linux with Examples
      Wireless networking plays a crucial role in modern computing, enabling devices to connect and communicate without the need for physical cables. In the Linux ecosystem, the iwconfig command stands as a powerful tool for configuring and managing wireless network interfaces. This article will delve int
      5 min read
      join Command in Linux
      The 'join' command in UNIX is a powerful command-line utility that allows you to merge lines from two files based on a common field, effectively combining related data into a more meaningful format. For instance, if you have one file with names and another with IDs, the join command can combine thes
      7 min read
      journalctl Command in Linux with Examples
      The `journalctl` command is part of the systemd suite of utilities and is used to query and display log messages from the systemd journal. The systemd journal is a centralized logging system that collects and stores log data from various sources, including system services, kernel events, and user ap
      7 min read
      How to Kill a Process in Linux | Kill Command
      kill command in Linux (located in /bin/kill), is a built-in command which is used to terminate processes manually. kill command sends a signal to a process that terminates the process. If the user doesn't specify any signal that is to be sent along with the kill command, then a default TERM signal i
      6 min read
      last command in Linux with Examples
      The 'last' command in Linux is a powerful utility used to display a list of all users who have logged in and out since the creation of the '/var/log/wtmp' file. It provides a chronological view of user sessions, allowing administrators to monitor user activity, troubleshoot issues, and manage system
      5 min read
      less command in Linux with Examples
      The 'less' command in Linux is an indispensable utility for browsing the contents of text files interactively. Unlike traditional text editors, 'less' allows you to view text files page by page without loading the entire file into memory. This approach not only speeds up the file loading process, es
      5 min read
      let command in Linux with Examples
      The `let` command in Linux is a powerful tool used for evaluating arithmetic expressions on shell variables. It supports various operators and functionalities to perform calculations and manipulate values. Syntax of `let` command in Linux The basic syntax of the `let` is as follows. let [expression]
      3 min read
      ln command in Linux with Examples
      The 'ln' command in Linux is a powerful utility that allows you to create links between files. These links can either be hard links or soft (symbolic) links. If you're unfamiliar with these concepts, check out our detailed guide on Hard and Soft Links in Linux to understand their differences, use ca
      3 min read
      locate command in Linux with Examples
      locate command in Linux is used to find the files by name. There are two most widely used file-searching utilities accessible to users called to find and locate. The locate utility works better and faster than the find command counterpart because instead of searching the file system when a file sear
      6 min read
    geeksforgeeks-footer-logo
    Corporate & Communications Address:
    A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
    Registered Address:
    K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
    GFG App on Play Store GFG App on App Store
    Advertise with us
    • Company
    • About Us
    • Legal
    • Privacy Policy
    • In Media
    • Contact Us
    • Advertise with us
    • GFG Corporate Solution
    • Placement Training Program
    • Languages
    • Python
    • Java
    • C++
    • PHP
    • GoLang
    • SQL
    • R Language
    • Android Tutorial
    • Tutorials Archive
    • DSA
    • Data Structures
    • Algorithms
    • DSA for Beginners
    • Basic DSA Problems
    • DSA Roadmap
    • Top 100 DSA Interview Problems
    • DSA Roadmap by Sandeep Jain
    • All Cheat Sheets
    • Data Science & ML
    • Data Science With Python
    • Data Science For Beginner
    • Machine Learning
    • ML Maths
    • Data Visualisation
    • Pandas
    • NumPy
    • NLP
    • Deep Learning
    • Web Technologies
    • HTML
    • CSS
    • JavaScript
    • TypeScript
    • ReactJS
    • NextJS
    • Bootstrap
    • Web Design
    • Python Tutorial
    • Python Programming Examples
    • Python Projects
    • Python Tkinter
    • Python Web Scraping
    • OpenCV Tutorial
    • Python Interview Question
    • Django
    • Computer Science
    • Operating Systems
    • Computer Network
    • Database Management System
    • Software Engineering
    • Digital Logic Design
    • Engineering Maths
    • Software Development
    • Software Testing
    • DevOps
    • Git
    • Linux
    • AWS
    • Docker
    • Kubernetes
    • Azure
    • GCP
    • DevOps Roadmap
    • System Design
    • High Level Design
    • Low Level Design
    • UML Diagrams
    • Interview Guide
    • Design Patterns
    • OOAD
    • System Design Bootcamp
    • Interview Questions
    • Inteview Preparation
    • Competitive Programming
    • Top DS or Algo for CP
    • Company-Wise Recruitment Process
    • Company-Wise Preparation
    • Aptitude Preparation
    • Puzzles
    • School Subjects
    • Mathematics
    • Physics
    • Chemistry
    • Biology
    • Social Science
    • English Grammar
    • Commerce
    • World GK
    • GeeksforGeeks Videos
    • DSA
    • Python
    • Java
    • C++
    • Web Development
    • Data Science
    • CS Subjects
    @GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
    We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
    Lightbox
    Improvement
    Suggest Changes
    Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
    geeksforgeeks-suggest-icon
    Create Improvement
    Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
    geeksforgeeks-improvement-icon
    Suggest Changes
    min 4 words, max Words Limit:1000

    Thank You!

    Your suggestions are valuable to us.

    What kind of Experience do you want to share?

    Interview Experiences
    Admission Experiences
    Career Journeys
    Work Experiences
    Campus Experiences
    Competitive Exam Experiences