I want to use command line to retrieve the total disk space on a machine as one value. On most Linux machines, the "df --total" returns such a value at the end of the regular df output.
On osx9, 10, 11, and 12, there seems to be no option like this.
[u'df: illegal option -- -\n', u'usage: df [-b | -H | -h | -k | -m | -g | -P] [-ailn] [-T type] [-t] [filesystem ...]\n']
Same issue with older linux os, redhat5, centos5, etc.
Another way to approach this? Is there another command to isolate certain values? I am mainly looking for the "total% used" value.
You'll have to calculate the value yourself, e.g. using awk:
df | awk '
BEGIN { SIZE=0; USED=0; AVAILABLE=0 }
// { print }
$3~/[0-9]/ { SIZE += $2; USED += $3; AVAILABLE += $4 }
END { printf "total\t%lu\t%lu\t%lu\t%d%%\n", SIZE, USED, AVAILABLE, (USED * 100 / SIZE); }'
to break it down
--total
's line)