i have a requirement to check the overall disk size of a linux server. is there any shell script to find the overall disk size.


serverA -- allocated with 5 disks of below size

sda - 100G sdb - 200G sdc - 200G sdd - 500G sde - 1TB

overall disk size of the linux server is 2TB. run a shell script to get the overall size = 2TB

can someone help on this.

Regards SUBASH

closed as off-topic by bodgit, HBruijn, womble Sep 21 at 8:26

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions on Server Fault must be about managing information technology systems in a business environment. Home and end-user computing questions may be asked on Super User, and questions about development, testing and development tools may be asked on Stack Overflow." – womble
If this question can be reworded to fit the rules in the help center, please edit the question.

  • Are you looking for total capacity of the disk or usable space on the filesystem? And are the disks mounted? Are any of them in raid? – Kefka Sep 18 at 14:47
  • Looking for the total size of the disks added to the server and not the file systems. for example: fdisk -l will list the disks available in the server. need the sum of all the disk size – subash ct Sep 18 at 14:54
  • Whatever you used to get the sizes of disks in human readable GB's and TB's probably also supports a flag to list the size in a more raw number. Sum those raw numbers (trivial) and only then (if needed) make a conversion to human readable GB's or TB's and you won't have deal with disparate units. Please not that the size of the "disk" an OS sees might not be the same as when your sytem uses a hardware raid controller – HBruijn Sep 18 at 14:59

There is exactly such a command! DF(1) is installed by default on most linux distributions:

df -h

The df command reports file system disk space usage. The -h option added above specifies that the disk sizes printed should use "human-readable" formatting (e.g. 10G instead of 1000000000).

The output of df -h should look something like this:

Filesystem       Size  Used Avail Use% Mounted on
udev              16G     0   16G   0% /dev
tmpfs            3.1G  940K  3.1G   1% /run
/dev/nvme0n1p1   7.6G  6.7G  993M  88% /
tmpfs             16G     0   16G   0% /dev/shm
tmpfs            5.0M     0  5.0M   0% /run/lock
tmpfs             16G     0   16G   0% /sys/fs/cgroup
/dev/loop1        79M   79M     0 100% /snap/core/7399
/dev/loop2        16M   16M     0 100% /snap/amazon-ssm-agent/1334
/dev/loop3        16M   16M     0 100% /snap/amazon-ssm-agent/1454
/dev/nvme0n1p15   98M  122K   98M   1% /boot/efi
/dev/nvme1n1     984G  852G   88G  91% /data
/dev/nvme2n1     984G  358G  576G  39% /data2
/dev/loop4        79M   79M     0 100% /snap/core/7716
tmpfs            3.1G     0  3.1G   0% /run/user/1000

To learn more about df and other commands you are curious about, use the man pages:

man df

EDIT: Props to @HBruijn for pointing out in the comments that disk space occupied by filesystem (revealed via df) and disk block-device size are not the same thing; for block-device info, use the command lsblk:


This command is human-readable by default, and you can customize the columns outputted with the -o flag (discover column options by running lsblk --help). For the options specified above, my machine reads out:

NAME         UUID                                  SIZE FSTYPE   TYPE MOUNTPOINT
loop1                                             78.5M squashfs loop /snap/core/7399
loop2                                             15.4M squashfs loop /snap/amazon-ssm-agent/1334
loop3                                             15.4M squashfs loop /snap/amazon-ssm-agent/1454
loop4                                             78.9M squashfs loop /snap/core/7716
nvme0n1                                              8G          disk 
├─nvme0n1p1  97edfc69-5417-46ce-b9a5-62bd731a4233  7.9G ext4     part /
└─nvme0n1p15 ED7D-760A                              99M vfat     part /boot/efi
nvme1n1      d1a6a2bb-8e53-4043-af05-f2e9ffa60c55 1000G ext4     disk /data
nvme2n1      b9d28a71-2d98-44a9-a37f-530effb88ba2 1000G ext4     disk /data2
  • The size of a disk (the spinning or solid state hardware device) is not the same as the size of a file-system (the logical representation of data stored on parts of 1 or more disks) – HBruijn Sep 18 at 15:03
  • Excellent point! Thanks for the feedback :) Indeed, if one wishes only to know the sizes of (possibly un-formatted) block devices, the command lsblk -o NAME,UUID,SIZE,FSTYPE,TYPE,MOUNTPOINT should suffice – Alex S Sep 18 at 15:11

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