howtouselinux

5 Ways to Check disk size in Linux

Table of Contents

Understanding device naming and usage are essential if we want to competently install and use disks in Linux. Device naming has changed and evolved over the numerous versions of Linux that are constantly being put out and as the technology changes.

To check the disk size in Linux, you can use lsblk, fdisk, or parted commands. All these commands are available in most Linux distributions.  They provide information about disk size, partition type, and mount point.

  • lsblk: This command will show you the block devices on your system in a tree-like format. With this command, you can see the total size for each device.
  • fdisk: This command is used to manipulate disk partitions. With fdisk, you can view the partition table, create new partitions, delete existing partitions and more.
  • parted: This command is used to create, resize and delete disk partitions. With parted, you can also view the partition table.

Related: 3 ways to check disk performance in Linux

Procedure to check disk size in Linux

  • Open the terminal.
  • Type sudo fdisk -l and press Enter.
  • The output will show information about the disk and partitions.
  • Type df -h and press Enter.
  • The output will show the disk partitions and their sizes as well as the amount of free space on each partition.

The following Linux commands can be used to check disk size.

  • lsblk -f
  • fdisk -l
  • parted -l
  • du -h shows disk usage in human-readable format for all directories and subdirectories
  • du -a shows disk usage for all files
  • df -h shows disk space in human-readable format

Related: 2 ways to check disk IOPS in Linux

Understanding Disk Naming standard

  • /dev/hd* – IDE disks. /dev/hda will be the first IDE hard disk, /dev/hdb will be second IDE hard disk, and so on.
  • /dev/sd* – SCSI or SATA disks including SSDs. /dev/sda will be the first SATA/SCSI hard disk, /dev/sdb will be second SATA/SCSI hard disk, and so on.
  • /dev/nvme* – NVM Express (NVMe) pci SSD. /dev/nvme0n1 will be first NVMe SSD, /dev/nvme1n1 will be second NVMe SSD, and so on.

 

Related: Understanding Disk Partition in Linux – MBR vs GPT

Check disk size with lsblk command in Linux

The best way to check disk size in Linux is using lsblk command. Open the terminal and type lsblk. Then press enter. This will print a list of all the disk devices on your system, as well as their size, type and mount point.

 This command reads the sysfs filesystem and udev db to gather information. 

To list all block devices, run:

 

  • lsblk
  • lsblk /dev/DEVICE
  • lsblk /dev/sda
  • lsblk -l
  • lsblk -d | grep disk

 

We can also fine-tune information displayed by lsblk as follows to list only Linux partitions and other data:

# lsblk -o NAME,FSTYPE,SIZE,MOUNTPOINT

In the following example, there are two disks vda and vdb. The size for vda is 160G. The size for vdb is 3.9T.

$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
vda 253:0 0 160G 0 disk
|-vda1 253:1 0 1G 0 part /boot
|-vda2 253:2 0 10G 0 part /var/tmp
|-vda3 253:3 0 9G 0 part /var
|-vda4 253:4 0 1K 0 part
|-vda5 253:5 0 6G 0 part /var/log
|-vda6 253:6 0 4G 0 part /home
|-vda7 253:7 0 3G 0 part [SWAP]
|-vda8 253:8 0 512M 0 part /var/log/audit
`-vda9 253:9 0 126.5G 0 part /
vdb 253:16 0 3.9T 0 disk /vdb

Related: 4 Ways to Check Disk Partition with Examples in Linux

Check disk size Using fdisk command in Linux

fdisk is a dialog-driven program for creation and manipulation of partition tables. It understands GPT, MBR, Sun, SGI and BSD partition tables.

The -l options shows the partition tables for the specified devices and then exit. If no devices are given, those mentioned in /proc/partitions (if that exists) are used. we can specify device name as follows (in this example list partitions for /dev/sda):

  • fdisk -l /dev/sda
  • fdisk -l

 

Check disk size with parted command in Linux

Parted is a famous command-line tool that allows us to easily manage hard disk partitions. It can help us add, delete, shrink and extend disk partitions along with the file systems located on them.

Partition Table (GPT) is a standard for the layout of the partition table on a physical hard disk. It is a part of the Extensible Firmware Interface (EFI) standard proposed by Intel as a replacement for the outdated PC BIOS, one of the few remaining relics of the original IBM PC. EFI uses GPT where BIOS uses a Master Boot Record (MBR).

In this example list partitions on /dev/sdb using the parted command:

Pass the -l OR –list option to the parted command to list partition layout on all block devices: # parted -l

Check Disk size Using sfdisk command in Linux

sfdisk command is a partition table editor. It is similar to fdisk and cfdisk, but with additional features.

This is very similar to fdisk, however sfdisk allows us to see both physical and logical volumes and also gives us a “summary” of the actual physical volumes’ partitions with the cylinders (start and end), sectors, size and type.

sfdisk -l device will list the partitions on the specified device. If the device argument is omitted, the partitions on all hard disks are listed. The following example lists the partitions on device /dev/hdc: sfdisk -l /dev/hdc

 

Check disks with blkid command in Linux

Prints the block device (partitions and storage media) attributes like uuid and file system type. Does not report the space on the partitions.

  • $ sudo blkid
  • /dev/sda1: UUID=”5E38BE8B38BE6227″ TYPE=”ntfs”
  • /dev/sda5: UUID=”4668484A68483B47″ TYPE=”ntfs”
  • /dev/sda6: UUID=”6fa5a72a-ba26-4588-a103-74bb6b33a763″ TYPE=”ext4″
  • /dev/sda7: UUID=”94443023-34a1-4428-8f65-2fb02e571dae” TYPE=”swap”
  • /dev/sda8: UUID=”13f35f59-f023-4d98-b06f-9dfaebefd6c1″ TYPE=”ext4″
  • /dev/sdb1: UUID=”08D1-8024″ TYPE=”vfat”

Linux command to check disk space

  • df command – Shows the amount of disk space used and available on Linux file systems.
  • du command – Display the amount of disk space used by the specified files and for each subdirectory.
David Cao
David Cao

Hey there! I am David, a Cloud & DevOps Enthusiast and 18 years of experience as a Linux engineer. I work with AWS, Git & GitHub, Linux, Python, Ansible, and Bash. I am a technical blogger and a Software Engineer, enjoy sharing my learning and contributing to open-source.