1

In my system, df -hT outputs something like this:

> df -hT 
Sist. Arq.     Tipo      Tam. Usado Disp. Uso% Montado em
devtmpfs       devtmpfs  1,9G  8,0K  1,9G   1% /dev
tmpfs          tmpfs     1,9G  616K  1,9G   1% /dev/shm
tmpfs          tmpfs     1,9G  1,8M  1,9G   1% /run
tmpfs          tmpfs     1,9G     0  1,9G   0% /sys/fs/cgroup
/dev/sda6      btrfs      80G   22G   58G  27% /
/dev/sda6      btrfs      80G   22G   58G  27% /.snapshots
/dev/sda6      btrfs      80G   22G   58G  27% /var/lib/pgsql
/dev/sda6      btrfs      80G   22G   58G  27% /var/lib/mysql
/dev/sda6      btrfs      80G   22G   58G  27% /var/opt
/dev/sda6      btrfs      80G   22G   58G  27% /var/lib/libvirt/images
/dev/sda6      btrfs      80G   22G   58G  27% /var/lib/mailman
/dev/sda6      btrfs      80G   22G   58G  27% /var/lib/machines
/dev/sda6      btrfs      80G   22G   58G  27% /var/crash
/dev/sda6      btrfs      80G   22G   58G  27% /var/lib/mariadb
/dev/sda6      btrfs      80G   22G   58G  27% /var/lib/named
/dev/sda6      btrfs      80G   22G   58G  27% /boot/grub2/x86_64-efi
/dev/sda6      btrfs      80G   22G   58G  27% /usr/local
/dev/sda6      btrfs      80G   22G   58G  27% /boot/grub2/i386-pc
/dev/sda6      btrfs      80G   22G   58G  27% /var/spool
/dev/sda6      btrfs      80G   22G   58G  27% /opt
/dev/sda6      btrfs      80G   22G   58G  27% /var/cache
/dev/sda6      btrfs      80G   22G   58G  27% /srv
/dev/sda6      btrfs      80G   22G   58G  27% /var/log
/dev/sda6      btrfs      80G   22G   58G  27% /var/tmp
/dev/sda6      btrfs      80G   22G   58G  27% /tmp
/dev/sda8      vfat      340G  313G   27G  93% /mnt/Data
/dev/sda7      xfs       200G  143G   58G  72% /home
tmpfs          tmpfs     385M   44K  385M   1% /run/user/1000
/dev/sda3      fuseblk   287G  190G   98G  67% /run/media/jaques/OS
/dev/mmcblk0p1 vfat      7,5G  2,1G  5,4G  28% /run/media/jaques/9843-A435

but I'd like to have each device listed only once, regardless how many times it gets mounted.

I'd like to have something simpler, like this:

> df -hT 
Sist. Arq.     Tipo      Tam. Usado Disp. Uso%
/dev/sda6      btrfs      80G   22G   58G  27%
/dev/sda8      vfat      340G  313G   27G  93%
/dev/sda7      xfs       200G  143G   58G  72%
/dev/sda3      fuseblk   287G  190G   98G  67%
/dev/mmcblk0p1 vfat      7,5G  2,1G  5,4G  28%

Is it possible? How?

System information, if needed:

OpenSuse Tumbleweed
Kernel 4.10.1

Thanks in advance.

j4x
  • 105
  • 7

1 Answers1

3

Well, it is easier to edit the output of df (for instance with awk) than to try to tweak its options. So what I would do is to define an alias

alias my_df="df -hT|awk -F% '$1!=p&&$1!~/tmpfs/{print $1 FS;p=$1}'" 

and use it whenever you want the reduced output. With the input you provided

$ my_df
Sist. Arq.     Tipo      Tam. Usado Disp. Uso%
/dev/sda6      btrfs      80G   22G   58G  27%
/dev/sda8      vfat      340G  313G   27G  93%
/dev/sda7      xfs       200G  143G   58G  72%
/dev/sda3      fuseblk   287G  190G   98G  67%
/dev/mmcblk0p1 vfat      7,5G  2,1G  5,4G  28%

Explanation: The output of df is piped through awk which, as instructed by -F%, splits each input line into two parts, $1 to be dealt with and $2 to be discarded. Then, if $1 is different from p (see below) and $1 does not match tmpfs, we print it with a final %. Finally, we assign the value of $1 to p so that, if the next line is the same as this one, we don’t print it.

Hope all is clear.

Dario
  • 831
  • 8
  • 11
  • Thanks @Dario. I though I would have to rely on something like that but you gave me the complete solution saving my little brain from thinking! – j4x Mar 17 '17 at 19:57