You can use awk
to format the numbers with %'d
then use column
to format the table
$ df | LC_ALL=en_US.UTF-8 awk '{
if (NR == 1) { print gensub(/ +/, "\t", "g") } else {
printf("%s\t%'"'"'d\t%'"'"'d\t%'"'"'d\t%d\t%s\n", $1, $2, $3, $4, $5, $6)
} }' | column -t -R 2,3,4,5 -s$'\t'
Filesystem 1K-blocks Used Available Use% Mounted on
dev 1,002,104 0 1,002,104 0 /dev
run 1,011,880 1,060 1,010,820 1 /run
/dev/sda2 36,285,808 17,358,124 17,054,752 51 /
tmpfs 1,011,880 0 1,011,880 0 /dev/shm
tmpfs 1,011,880 0 1,011,880 0 /sys/fs/cgroup
tmpfs 1,011,880 8,300 1,003,580 1 /tmp
/dev/sda1 306,584 264 306,320 1 /boot/efi
tmpfs 202,376 28 202,348 1 /run/user/1000
/dev/sr0 58,122 58,122 0 100 /run/media/mypc/myfolder
By setting the locale with LC_ALL
you can change to any thousand formats available out there. You can also remove the -R
option if you don't want to right-align the numbers or your column
version doesn't have that option (like the default one on Ubuntu)
If you get the function gensub never defined
error then it's because of this bug which can be solved by installing gawk. Alternatively change the delimiter to space instead of tab:
df | LC_ALL=en_US.UTF-8 awk '{
if (NR == 1) { print } else {
printf("%s\t%'"'"'d\t%'"'"'d\t%'"'"'d\t%d\t%s\n", $1, $2, $3, $4, $5, $6)
} }' | column -t
If you want to get the KB value you'll need to divide the corresponding columns
df | LC_ALL=en_US.UTF-8 awk -v K=1024 '{
if (NR == 1) { print gensub(/ +/, "\t", "g") }
else { printf("%s\t%'"'"'d\t%'"'"'d\t%'"'"'d\t%d\t%s\n",
$1, $2/K, $3/K, $4/K, $5, $6) } }
' | column -t -R 2,3,4,5 -s$'\t'
If you want to get a floating-point value just change %d
to %f
df | LC_ALL=en_US.UTF-8 awk -v K=1024 '{
if (NR == 1) { print gensub(/ +/, "\t", "g") }
else { printf("%s\t%'"'"'0.2f\t%'"'"'0.2f\t%'"'"'0.2f\t%d\t%s\n",
$1, $2/K, $3/K, $4/K, $5, $6) } }
' | column -t -R 2,3,4,5 -s$'\t'
Of course you can also align the columns directly from awk
with the field width option like printf "%-10d %10d\n", $1, $2
without needing column
but you'll have to reserve enough space for each column
df
internally useslconv::thousands_sep
. How to set it, no idea.-h
/--human-readable
, it is used. In other formats probably not.