Introducing how to improve the readability of df using the Bash command awk in the Linux command line language Bash.
awk is interesting.
df
df: /mnt/_share: Transport endpoint is not connected
df: /mnt/_share: Transport endpoint is not connected
df: /mnt/_share: Transport endpoint is not connected
Filesystem 1K-blocks Used Available Use% Mounted on
rootfs 975731888 913886036 61845852 94% /
root 975731888 913886036 61845852 94% /root
home 975731888 913886036 61845852 94% /home
data 975731888 913886036 61845852 94% /data
cache 975731888 913886036 61845852 94% /cache
mnt 975731888 913886036 61845852 94% /mnt
none 975731888 913886036 61845852 94% /dev
none 975731888 913886036 61845852 94% /run
none 975731888 913886036 61845852 94% /run/lock
none 975731888 913886036 61845852 94% /run/shm
none 975731888 913886036 61845852 94% /run/user
C: 975731888 913886036 61845852 94% /mnt/c
E: 2930133932 381876300 2548257632 14% /mnt/e
G: 2930133932 1545875952 1384257980 53% /mnt/g
H: 2930134012 2625853000 304281012 90% /mnt/h
color df 2>/dev/null | awk '{if ($1 ~ /\w{1}:/){print $1,$5,$6}}'
C: 94% /mnt/c
E: 14% /mnt/e
G: 53% /mnt/g
H: 90% /mnt/h
I wanted to convert the byte count to GB by passing it to Python for division, but I didn’t know how because the command execution was a bit complex.
awk - Assigning system command’s output to variable - Stack Overflow
(Added) I got it working. I posted an article.
Some documentation references for awk.
AWK Cheat Sheet | ShortcutFoo AWK cheatsheet
I improved it.
color df 2>/dev/null | awk '{if ($1 ~ /\w{1}:/){"python -c \"print("$4"/1000/1000)\" | perl -pe 'chomp'" |& getline $11 ; print $1,$11"(GB)",$5,$6}}'
C: 61(GB) 94% /mnt/c
E: 2548(GB) 14% /mnt/e
G: 1384(GB) 53% /mnt/g
H: 304(GB) 90% /mnt/h
(Added in 2021: Isn’t this just “df -h”? I don’t really understand what I was trying to do back then.