Linux Commands

Linux Commands to Check Disk Partitions

On Linux, the disk partitions are made by dividing the secondary storage drives. These partitions are useful to manage the storage efficiently. Knowing how to monitor the disk partitions is important for managing storage on Linux. Various command-line tools are used to check disk partitions on Linux.

In this tutorial, I will list commonly used command-line utilities to check disk partitions on Linux.

Linux Commands to Check Disk Partitions

Linux is an open-source operating system that provides various command-line tools to check disk partitions. Many utilities come pre-installed on Linux, while some need to be installed.

Built-in Linux commands to check partitions:

  • fdisk
  • cfdisk
  • sfdisk
  • lsblk
  • blkid
  • df

Third-party commands to check the partitions:

  • parted
  • hwinfo
  • pydf

Check Disk Partitions on Linux using Built-in Commands

Let’s begin with the built-in utilities to check the disk partitions on Linux. Tools like fdisk, cfdisk, and sfdisk are used to manage partitions on Linux but provide different interfaces. While lsblk and blkid are used to list block devices and their associated partitions. However, both differ in various aspects. The lsblk simply lists the block devices and partitions while blkid displays more parameters like UUIDs, file system types, and labels.

Using fdisk Command

The first command to check the disk partition is using the fdisk command with the -l option. It is used to create and manipulate the disk partition, and using the -l flag with it lists the partitions table.

To check the partitions of all the block devices, use the following command. To run this command, you need sudo privileges.

sudo fdisk -l

To check the disk partition of a specific block device, mention the device name after fdisk -l command.

sudo fdisk -l /dev/vda

Here, the /dev/vda signifies the first disk using a virtualization-aware disk driver because the command is being executed on a guest operating system. It will be /dev/sda if the storage drive is connected to the system via SCSI, SATA, or IDE connections.

Using cfdisk Command

The cfdisk is another curses-based tool for creating, deleting, and resizing the partitions on Linux. This command lists all the partitions when executed with sudo.

sudo cfdisk

It can also be used to get partitions of a specific drive. Just mention the drive name after the command, such as sudo cfdisk /dev/sda.

Using sfdisk Command

The sfdisk is another command-line utility used to manage the hard disk partitions. It can be used to check the partitions of the hard drive.

sudo sfdisk -l

Using lsblk Command

The lsblk tool is used to list all the available block devices. It also shows the partitions of the main block device.

lsblk

To display more information about the block devices, use the -f flag.

Using blkid Command

The blkid command is also used to list the block devices and their attributes like types, names, labels, block sizes, and UUIDs. It also lists the disk partitions along with types and PARTUUIDs.

blkid

Using df Command

The df command is generally used to check the space available on the mounted file system. It can also be used to check partitions with flags like -a for all, -m for megabytes, and -h for human-readable format.

df

Check Disk Partitions on Linux using Third-party Commands

Many open-source third-party utilities can be used to check the disk partitions. They are improved versions of built-in commands and provide clearer and human-readable output. The system doesn’t have these utilities by default; you have to install them.

Using parted Command

The parted command-line tool is used to create, delete, and resize the partitions on Linux. To open the parted interface, use the parted command with sudo privileges.

sudo parted

It does not directly list the partitions; after executing the command, type help.

Now, execute the print command with the list option.

print list,all

To close the parted interface, type quit and then press the Enter key.

Using hwinfo Command

The hwinfo is used to troubleshoot system hardware. This utility comes with a range of options to list the hardware information. It can also be used to list the block devices and partitions using the –block option.

hwinfo --short --block

Using pydf Command

The pydf is a Python script that prints the amount of space available on the mounted file system. It essentially enhances the functionality of the df utility.

pydf

Conclusion

Disk management is the most crucial part of maintaining the system. To check whether your system has partitions or not, Linux offers many tools. Many are built-in Linux, while some are third-party improved versions of the built-in tools.

This guide lists all the built-in and third-party command-line tools to check the disk partitions on Linux. The quickest way to check the disk partition is using the lsblk command, which lists all the available drives and their partitions.

About the author

Sam U

I am a professional graphics designer with over 6 years of experience. Currently doing research in virtual reality, augmented reality and mixed reality.
I hardly watch movies but love to read tech related books and articles.