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?
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.
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
468G
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.
blocks * block's size
as fdisks's usual result are in blocks, sectors?
Jan 3, 2014 at 15:57