2024-02-15
lsblk?lsblk (list block devices) is a simple yet powerful command-line utility used to display information about block devices on a Linux system. These block devices represent storage devices like hard drives, SSDs, partitions, and even loop devices (used for mounting image files). Unlike commands like fdisk which modify partitions, lsblk is purely for informational purposes.
The simplest way to use lsblk is to run it without any options:
lsblkThis will output a table showing the block devices, their mount points (if mounted), and some key properties. You’ll see information like:
/dev/sda, /dev/sdb1).lsblk Optionslsblk offers many options to customize the output and tailor it to your specific needs:
-l (List)This option provides a more concise, single-line output, perfect for scripting or when you need a quick overview:
lsblk -lThe output will show key information in a compact format, omitting some less critical details.
-f (Full Output)The -f option provides more details than the default output. This includes the filesystem type of each partition:
lsblk -fThis is extremely useful for identifying the filesystem on various partitions.
-o (Output Columns)This option allows you to specify which columns are displayed. You can list multiple columns separated by commas. For example, to only show the NAME and SIZE:
lsblk -o NAME,SIZEYou can find a complete list of available columns in the lsblk man page (man lsblk).
-n (No headers)Suppress the header line from the output. This is handy when parsing the output with other commands:
lsblk -n-p (Print all)This option will display all partitions, even those that are not in use:
lsblk -p-e and -t-e <type>: allows you to specify the types of devices to list (e.g., -e part for partitions only)-t <type>: opposite of -e, this filters to show only devices of a specified type (e.g., -t disk for disks only).Example showing only partitions:
lsblk -e partExample showing only disks:
lsblk -t diskThese options provide a significant level of control over the output of lsblk, making it a tool for managing and monitoring your Linux system’s block devices. By combining these options effectively, you can extract precisely the information you need in the format you prefer.