lsblk Command in Linux

Learn via video courses
Topics Covered

Transform Your Career

Choose from our industry-leading programs designed for career success

NSDC Certified

Modern Software and AI Engineering Program

Master full-stack development with AI integration

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Modern Data Science and ML with specialisation in AI

Advanced data science techniques with AI specialization

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Advanced AIML with Specialisation in Agentic AI

Deep dive into AIML with focus on Agentic systems

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

DevOps, Cloud & AI Platform Engineering

Build and manage AI-powered cloud infrastructure

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

AI Engineering Advanced Certification by IIT-Roorkee

Premier AI engineering certification from IIT-Roorkee

3 MonthsDuration
AI-LedCurriculum
Career SupportSupport
Program highlights
Go to Program

Overview

Welcome to the world of Linux commands where we take a deep dive into the lsblk command in Linux. The 'lsblk' stands for 'list block devices', and as the name suggests, it is used to list out all block devices in a tree-like format. This powerful command can help you gather comprehensive information about each block device connected to your Linux system, including the disk partitions and their respective sizes.

Syntax of lsblk Command in Linux

The basic syntax of the lsblk command in Linux is as follows:

Where:

  • options: These are the flags or parameters that can be used with the lsblk command to modify its output or behavior.
  • device: This refers to the specific block device(s) that you want to display information for. If no device is specified, lsblk will display information for all block devices.
Free Courses by top Scaler instructors
Python Course for Beginners With Certification: Mastering the Essentials
Java Course - Mastering the Fundamentals
DBMS Course - Master the Fundamentals and Advanced Concepts
JavaScript Course With Certification: Unlocking the Power of JavaScript
C++ Course: Learn the Essentials
Python and SQL for Data Science Course
Python Course for Beginners With Certification: Mastering the Essentials
Java Course - Mastering the Fundamentals
DBMS Course - Master the Fundamentals and Advanced Concepts
JavaScript Course With Certification: Unlocking the Power of JavaScript
C++ Course: Learn the Essentials
Python and SQL for Data Science Course

Options in lsblk Command in Linux

  1. -a, --all: Shows all block devices, including the empty ones.

    For example -

    Output:

    This command lists out all block devices, even if they don't have any filesystems mounted on them.

  2. -b, --bytes: Prints the size in bytes instead of in a human-readable format.

    For example -

    Output:

    This command displays the size of the block devices in bytes, which can be useful when precise measurements are required.

  3. -o, --output [list]: Allows you to customize the output by specifying a comma-separated list of column names.

    For example -

    Output:

    This command customizes the output of the lsblk command to only display the name and size of each block device.

Scaler Placement Report and Statistics

₹23L
AVG CTC
SCALER PLACEMENT PROOF

Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.

11,000+placements
650+companies
Verified data
Hiring Partners:
GoogleGoogleAmazonAmazonMicrosoftMicrosoftFlipkartFlipkartAdobeAdobe1200+ more

Example Usages

  • Basic usage of lsblk command:

    Output:

    Explanation: Without any options, the lsblk command in Linux lists out all block devices, along with relevant information such as their size, type, and mountpoint.

  • Using lsblk command to display specific devices:

    Output:

    Explanation: By specifying a device in the command, lsblk only displays information about that particular device.

Tips

  • The lsblk command in Linux is a great way to get an overview of your system's storage devices. However, for detailed disk usage statistics, consider using the 'df' command.

  • Remember to run the 'lsblk' command with superuser privileges (using sudo) if you're not seeing all the information you expect.

Turn Learning into Career Growth

1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary
1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary

Advanced Use Cases of lsblk Command in Linux

  • Using lsblk to display the UUID and file system type of devices:

    Output:

    Explanation: This advanced usage of the lsblk command in Linux allows you to display the UUID and file system type of block devices, which can be useful for troubleshooting and system configuration.

  • Using lsblk to display the read-only block devices:

    Output:

    Explanation: This advanced usage of the lsblk command helps you to identify the read-only block devices in your system.

  • Using lsblk to exclude certain types of devices:

    Output:

    Explanation: The '-e' option allows you to exclude devices by their major number, providing a more focused output.

Conclusion

  • The lsblk command in Linux provides a comprehensive way to view information about all block devices in a system.

  • It offers a range of options to tailor the output according to your needs.

  • Advanced usages include displaying the UUID and file system type of devices, identifying read-only devices, and excluding certain types of devices.