I've already tried du-ch , df -h and df -h --total but it all result to their specific size of folder. Need to know how can I get the total used space in human readable form. Hoping for your help. Thanks in advance.
2 Answers
First of all, let's clarify a few things. When you do df -h --total
, there are a few things that show virtual filesystems, such as tmpfs
and udev
. We don't exactly want that, but we want to know all physical filesystems. As such, we want to filter out only /dev
items:
$ df -h | grep '^/dev/'
/dev/sda1 110G 77G 29G 74% /
/dev/sdb6 399G 223G 157G 59% /mnt/HDD
But there's a problem, too: -h
gives us total in human-readable format. We can't really add up items that have letters in them. grep
also can't perform calculations. Thus, instead lets use awk
instead, with summing the 3rd column:
$ df --block-size=1 | awk '/^\/dev/{total+=$3}END{print total}'
320762605568
Great ! now we only need to find the human readable version of that number. We can always write code in awk to do that, but there already exists numfmt
utility. So we can do this:
$ df --block-size=1 | awk '/^\/dev/{total+=$3}END{print total}' | numfmt --to=iec-i --suffix=B --padding=7
299GiB
And that's how you have the total of all physical devices that are mounted ( which is what df
shows by default).
You need to use it like so:
df -h --total / | grep total | awk '{ print $3 }'
Or:
df -h --total . | grep total | awk '{ print $3 }'
Result:
599G
-
What is the point of
--total
when specifying a single path? maybe an example which uses two path will be more helpful ;)– Ravexina ♦Commented Jul 10, 2017 at 20:32 -