0

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
  • Already used df -h --total but it says that df: unrecognized option `--total' Commented Jul 10, 2017 at 20:08
  • What is your Ubuntu version?
    – Ravexina
    Commented Jul 10, 2017 at 20:33

2 Answers 2

1

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).

0
0

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
2
  • 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
  • Let me update that. Commented Jul 10, 2017 at 20:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .