How to check a vendor's statement about a hard disk size? df shows results partition oriented (including tmpfs), one has to execute it and count label oriented.

How to get in a single command or cat /proc's file the hard disk size?

3 Answers 3


hdparm, when invoked with the -I switch, displays identification info directly requested from the drive. This includes the drive's size and pretty pretty much everything else you could be interested in.

To display only the drive's size, you can use this command:

sudo hdparm -I /dev/sdX | grep "device size"

A word of caution: hdparm requires root access and is a potentially destructive tool. While the -I switch is perfectly safe to use, others aren't.

  • thanks, that's what I was looking for. I also found the following: sudo parted -l... helpful. Jan 3, 2014 at 16:09

There are various methods actually, Not all of these programs will be installed by default but all will be easily available on any GNU/Linux distribution:

$ sudo lshw | grep -A 15 disk | grep size
             size: 465GiB (500GB)
$ df --total -TH --exclude-type=tmpfs | awk '{print $3}' | tail -n 1

hdparm and fdisk -l have already been mentioned but you could do

$ sudo fdisk -l | grep "^Disk /" | gawk '{print $3,$4}'
500.1 GB,

While not the easiest to parse, and not recommended for scripting purposes, fdisk -l /dev/sdX should give you the information you're looking for.

  • thanks, do you know how to calc without the need of multipling blocks * block's size as fdisks's usual result are in blocks, sectors? Jan 3, 2014 at 15:57
  • plus, does fdisk consider tmpfs? Jan 3, 2014 at 16:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.