?

Log in

No account? Create an account

Josh-D. S. Davis

Xaminmo / Omnimax / Max Omni / Mad Scientist / Midnight Shadow / Radiation Master

Previous Entry Share Next Entry
Tired of df having poor column control
Josh 201604 KWP
joshdavis
Linux's "display filesystems" command is formatted base don the assumption that all of your devices will be /dev/hda# or /dev/md#. When you're dealing with a volume group, things are a bit more messy:

/bin/bash# df -T
Filesystem    Type   1K-blocks      Used Available Use% Mounted on
/dev/mapper/rootvg-hd4
              ext3      507748    323923    157630  68% /
tmpfs        tmpfs     2042208         0   2042208   0% /lib/init/rw
udev         tmpfs       10240       184     10056   2% /dev
tmpfs        tmpfs     2042208         4   2042204   1% /dev/shm
/dev/md0      ext3      256586     74785    168553  31% /boot
/dev/mapper/rootvg-hd3
               jfs    52394228    780352  51613876   2% /home
/dev/mapper/rootvg-hd10
               jfs     8355380     46304   8309076   1% /opt
/dev/mapper/rootvg-hd1
              ext3     1032088     34176    945484   4% /tmp
/dev/mapper/rootvg-hd2
              ext3     3096336   2484120    454944  85% /usr
/dev/mapper/rootvg-hd9
               jfs     8355380   3226012   5129368  39% /var

As you can see, it's a bit messy for my volume group. If we shrink the fields to "Human readable" sizes, and use POSIX mode, it's a little better....

[xaminmo@ns1:/home/xaminmo]
/bin/bash# df -THP
Filesystem    Type     Size   Used  Avail Use% Mounted on
/dev/mapper/rootvg-hd4 ext3   520M   332M   162M  68% /
tmpfs        tmpfs     2.1G      0   2.1G   0% /lib/init/rw
udev         tmpfs      11M   189k    11M   2% /dev
tmpfs        tmpfs     2.1G   4.1k   2.1G   1% /dev/shm
/dev/md0      ext3     263M    77M   173M  31% /boot
/dev/mapper/rootvg-hd3 jfs    54G   800M    53G   2% /home
/dev/mapper/rootvg-hd10 jfs   8.6G    48M   8.6G   1% /opt
/dev/mapper/rootvg-hd1 ext3   1.1G    35M   969M   4% /tmp
/dev/mapper/rootvg-hd2 ext3   3.2G   2.6G   466M  85% /usr
/dev/mapper/rootvg-hd9 jfs   8.6G   3.4G   5.3G  39% /var

As you can see, now the columns don't line up. It's messy and hard to visually process.

There are no options to maintain column boundaries within normal DF, while keeping everything on one line. But, it's easy to make a little awk powered script to do what I want:

[xaminmo@ns1:/home/xaminmo]
/bin/bash# ndf
Filesystem                            Type   Size   Used  Avail  Use% Mounted
/dev/mapper/rootvg-hd4                ext3   520M   332M   162M   68% /
tmpfs                                tmpfs   2.1G      0   2.1G    0% /lib/init/rw
udev                                 tmpfs    11M   189k    11M    2% /dev
tmpfs                                tmpfs   2.1G   4.1k   2.1G    1% /dev/shm
/dev/md0                              ext3   263M    77M   173M   31% /boot
/dev/mapper/rootvg-hd3                 jfs    54G   800M    53G    2% /home
/dev/mapper/rootvg-hd10                jfs   8.6G    48M   8.6G    1% /opt
/dev/mapper/rootvg-hd1                ext3   1.1G    35M   969M    4% /tmp
/dev/mapper/rootvg-hd2                ext3   3.2G   2.6G   466M   85% /usr
/dev/mapper/rootvg-hd9                 jfs   8.6G   3.4G   5.3G   39% /var

Now, I took the lazy route. This is just a simple filter. The column widths are fixed.

The appropriate thing to do would be to read in the columns, determine the max width of any given item, pad with 2 chars, and then output a completely synthetic table.

Maybe, sometime, if I were really motivated. But for now, we'll leave it at this:

[xaminmo@ns1:/home/xaminmo]
/bin/bash# cat bin/ndf
#!/bin/bash

df -THP | \
awk '{
        printf "%-30s", $1;
        printf "%12s", $2;
        printf "%7s", $3;
        printf "%7s", $4;
        printf "%7s", $5;
        printf "%6s", $6;
        printf " %-20s\n", $7;
}'

echo