Thursday, April 28, 2016

Formatting the output of df-h with limited fields.

Normal output of df -h:

-bash-4.1$ df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_misc-root
                       29G   18G   10G  64% /
tmpfs                 1.9G  668M  1.3G  35% /dev/shm
/dev/sda1            1008M  104M  854M  11% /boot
/dev/mapper/vg_misc-logs
                      4.9G  138M  4.5G   3% /logs

Formatted output of df -h in single line:

-bash-4.1$ df -Ph | column -t
Filesystem                         Size     Used   Avail  Use%  Mounted          on
/dev/mapper/vg_misc-root   29G     18G     10G    64%     /
tmpfs                                  1.9G     668M  1.3G   35%     /dev/shm
/dev/sda1                            1008M 104M  854M 11%     /boot
/dev/mapper/vg_misc-logs   4.9G     138M  4.5G   3%      /logs

Showing specific fields in output of df -h:

-bash-4.1$ df -Ph | column -t | awk '{print $2,$6}'
Size Mounted
29G /
1.9G /dev/shm
1008M /boot
4.9G /logs
11G /tmp

No comments: