Notes

[df] Disk Free

Edit on GitHub


Commands
2 minutes
1df -h

The -h flag is for human readable output, show 30G instead of 30830588.

Screenshot df -h

Summing numbers in the output of df

We can do that by pip the output of the df command to something like awk and have awk sum up the numbers, like so:

1df -lP | awk '{}'
2df -lP | awk '{do math} END {print result}'

If the device names are long, df splits the output on multiple line to fit it in the normal 80 character long terminal. -P is for portability, use the POSIX output format (and not try to fit everything in by breaking lines) Get the foramt data in a consistent format, every device on one line.

FYI: You can also get a nicer output y piping the output to column

1df -lP | column -t

(To me it just looks like column -t right aligned the column data..)

Screenshot df -lp

So, back to summing..

1df -lP | awk '{sum += $3}'

the sum variable is equal to the sum of values in the third column $3 (take the value of sum and add the third column to it).

1df -lP | awk '{sum += $3} END { printf sum }'
2# 314098258

Get the sum and and at the end of it, print the value of sum.

1df -lP | awk '{sum += $3} END { printf "%d GiB\n", sum/2^20}'
2# 299 GiB

Screenshot df -lp | awk