Take the 2-minute tour ×

What is the command line command to get the number of physical disks in Linux Server and how much space is used on each?

share|improve this question
add comment

3 Answers

up vote 6 down vote accepted

sudo fdisk -l will list your disks and a bunch of stats about them, including the partitions. The disks are generally in the form of /dev/sdx and partitions /dev/sdxn, where x is a letter and n is a number (so sda is the first physical disk and sda1 is the first partition on that disk).

sudo df -h gives you the size and usage stats per partition. Drop the -h and you get usage in blocks, with it it's human readable.

I put the sudos in there because I got no output from fdisk and only partial output from df when I ran the commands as a regular user, I suppose because the commands read from somewhere off limits to non-admins.

share|improve this answer
Hey, code formatting. Thanks. –  ChimneyImp Jul 31 '12 at 20:33
add comment

You'd think there'd be a simple answer to this, but it actually depends on what you mean by "physical disk". iSCSI volumes and RAID devices (for example) appear as physical disks, but the tools one uses to examine these differ.

If you just mean a plain SATA or SCSI drive attached directly to a host controller on the motherboard of the server, you're looking for actively used devices located at /dev/sdN, so you can grep through your dmesg for them (dmesg | grep sd) or you could look in /dev/disk/by-id or yet again you can look in /proc/diskstats.

Once you've identified the /dev/ entry for devices that are present, you can use the appropriate tool to check for free space. This again depends on other info, such as how they were partitioned, whether they use the lvm, and so on.

share|improve this answer
One other point: my answer was assuming that you might want to partition a disk, modify it's lvm layout, or create/modify filesystems. If you just want to know how much free space is available on already allocated disk, run the command "df -h" –  sapeurfaire Jul 31 '12 at 17:50
Actually, this question is motivated by stackoverflow.com/questions/11744730/…. I want to know actually, how many separate disk systems are in our server machine. (Tomas Answer). –  Arpssss Jul 31 '12 at 17:53
How many are available, or how many are in use? In other words, are you looking for a place to put another disk, or are you trying to find a disk you think is already there? –  sapeurfaire Jul 31 '12 at 18:06
I am trying to find a disk that I think is already there. –  Arpssss Jul 31 '12 at 18:16
add comment

I think the easiest way (at least concerning parsing effort) on a recent Linux installation would be

$ lsblk -S

which outputs something like this:

tremendous:~# lsblk -S
sda  0:0:0:0    disk ATA      WDC WD5000AUDX-6 01.0 sata
sdb  1:0:0:0    disk ATA      WDC WD5000AUDX-6 01.0 sata
share|improve this answer
-S is not a valid option on debian wheezy/sid or Ubuntu 12.10. Without it, however, lsblk displays a nice forest-like output. –  dezso Mar 31 at 9:51
add comment

Your Answer


