If you want to find the total amount of disk space used on Linux, and other Unix based systems (such as OSX), you can do so quite easily with the following one liner…
df -lP | awk '{total+=$3} END {printf "%d G\n", total/2^20 + 0.5}'
What this does is…
- df -lP … shows a disk report of all local disks, in posix format (e.g. one line per volume)
- | awk ‘{total+=$3} END {printf “%d G\n”, total/2^20 + 0.5}’ … this takes the output of the df command, pipes it to awk which then sums the 3rd columns into a variable called total, and when it’s finished it prints out this number converted to Gigabytes. To get to Gigabytes, we divided by 2^20 (1024*1024), and we also add 0.5 so that it is effectively rounded to the nearest whole number.
This is particularly helpful if you have a lot of volumes on a system.
Nice – very useful. Thanks for sharing 🙂
Try
df -h –total
cheers