Tuesday 19 March 2019

Cleaning up df output

I use df a lot on ubuntu. Unfortunately with advent of snap devices df output has become increasingly cluttered with various devices mounted by the system that I generally don' have an interest in seeing.

For example:

# /bin/df
Filesystem      1K-blocks       Used Available Use% Mounted on
udev              8121812          0   8121812   0% /dev
tmpfs             1630708       1888   1628820   1% /run
/dev/sda1        30627388   15252072  13796484  53% /
tmpfs             8153528      68012   8085516   1% /dev/shm
tmpfs                5120          4      5116   1% /run/lock
tmpfs             8153528          0   8153528   0% /sys/fs/cgroup
/dev/loop1          93184      93184         0 100% /snap/core/6405
/dev/loop2          93184      93184         0 100% /snap/core/6350
/dev/loop4          35456      35456         0 100% /snap/gtk-common-themes/818
/dev/loop7          35712      35712         0 100% /snap/gtk-common-themes/1122
/dev/sda2        76766240   26915652  45927952  37% /home
/dev/sdb       7814026584 7137072996 674941212  92% /mnt/library
/dev/sdc       3907018584 3436394816 467552000  89% /mnt/archive
tmpfs             1630704         16   1630688   1% /run/user/132
tmpfs             1630704         80   1630624   1% /run/user/1000
/dev/loop8          36224      36224         0 100% /snap/gtk-common-themes/1198
/dev/loop9          93312      93312         0 100% /snap/core/6531
/dev/loop0       48768594   48768594         0 100% /mnt/loop/Archive.TV.01
/dev/loop3       48628258   48628258         0 100% /mnt/loop/Archive.TV.02
/dev/loop5       48845728   48845728         0 100% /mnt/loop/Archive.TV.03


So that you don't have to visually hunt through that junk to see what you need add this to your users .bashrc file:

function df
{
  /bin/df "$@" | grep -v loop | grep -v tmpfs | grep -v udev
}

Now your df output just lists the actual mounted drives:

#df
Filesystem      1K-blocks       Used Available Use% Mounted on
/dev/sda1        30627388   15252080  13796476  53% /
/dev/sda2        76766240   26915652  45927952  37% /home
/dev/sdb       7814026584 7137072996 674941212  92% /mnt/library
/dev/sdc       3907018584 3436700752 467246064  89% /mnt/archive
/dev/loop0       48768594   48768594         0 100% /mnt/loop/Archive.TV.01
/dev/loop3       48628258   48628258         0 100% /mnt/loop/Archive.TV.02
/dev/loop5       48845728   48845728         0 100% /mnt/loop/Archive.TV.03

If you want see the full output use the full path /bin/df

No comments: