Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

EASILY View Disk Usage in Linux with DUF

How do you check disk usage in Linux? I’m sure that is a question many of us have wondered especially when first learning Linux. There are many tools out there that can help us view this information about our system. In my opinion, a lot of them just look ugly, simple to understand but still ugly – I’m a man of style! So that is why we’re going to take a look at the duf command found on GitHub. It is very informative, written in GoLang and has a few handy features some of you might find useful like exporting data as JSON.

Installing DUF

If you’re lucky, duf might be in your local repository but sadly for me on Ubuntu 20.04 LTS, it was not. So lets go over installing it from the repository and manually downloading the package.

If the package is not in your repository, then head over to the releases page to manually download the right package for your system and architecture from the GitHub releases page.

Ubuntu/Debian

sudo apt install duf

Arch/Garuda

sudo pacman -Sy duf

Fedora/RHEL

sudo dnf install duf

Basic Usage

At the very most basic level, simply run the command duf and you will get the following output.

╭─────────────────────────────────────────────────────────────────────────────────────────╮
│ 2 local devices                                                                         │
├────────────┬────────┬──────┬────────┬───────────────────────────────┬──────┬────────────┤
│ MOUNTED ON │   SIZE │ USED │  AVAIL │              USE%             │ TYPE │ FILESYSTEM │
├────────────┼────────┼──────┼────────┼───────────────────────────────┼──────┼────────────┤
│ /          │  19.1G │ 6.9G │  11.1G │ [#######.............]  36.4% │ ext4 │ /dev/vda5  │
│ /boot/efi  │ 511.0M │ 4.0K │ 511.0M │ [....................]   0.0% │ vfat │ /dev/vda1  │
╰────────────┴────────┴──────┴────────┴───────────────────────────────┴──────┴────────────╯
╭──────────────────────────────────────────────────────────────────────────────────────────────────╮
│ 7 special devices                                                                                │
├────────────────┬────────┬───────┬────────┬───────────────────────────────┬──────────┬────────────┤
│ MOUNTED ON     │   SIZE │  USED │  AVAIL │              USE%             │ TYPE     │ FILESYSTEM │
├────────────────┼────────┼───────┼────────┼───────────────────────────────┼──────────┼────────────┤
│ /dev           │   1.9G │    0B │   1.9G │                               │ devtmpfs │ udev       │
│ /dev/shm       │   1.9G │    0B │   1.9G │                               │ tmpfs    │ tmpfs      │
│ /run           │ 392.6M │  1.4M │ 391.2M │ [....................]   0.4% │ tmpfs    │ tmpfs      │
│ /run/lock      │   5.0M │  4.0K │   5.0M │ [....................]   0.1% │ tmpfs    │ tmpfs      │
│ /run/user/1000 │ 392.6M │  8.0K │ 392.6M │ [....................]   0.0% │ tmpfs    │ tmpfs      │
│ /run/user/1001 │ 392.6M │ 20.0K │ 392.6M │ [....................]   0.0% │ tmpfs    │ tmpfs      │
│ /sys/fs/cgroup │   1.9G │    0B │   1.9G │                               │ tmpfs    │ tmpfs      │
╰────────────────┴────────┴───────┴────────┴───────────────────────────────┴──────────┴────────────╯

Doesn’t that just look pretty?

Checking Directory/Mount Usage

For most users the default output from duf should be more than enough especially if you’re only interested in usage at-a-glance. So on the machine I’m working on, I have added 2 additional drives of 5G each. Notice how in the last output, you do not see them. This is because we first have to mount them so I will do that now and re-run duf.

╭──────────────────────────────────────────────────────────────────────────────────────────╮
│ 4 local devices                                                                          │
├────────────┬────────┬───────┬────────┬───────────────────────────────┬──────┬────────────┤
│ MOUNTED ON │   SIZE │  USED │  AVAIL │              USE%             │ TYPE │ FILESYSTEM │
├────────────┼────────┼───────┼────────┼───────────────────────────────┼──────┼────────────┤
│ /          │  19.1G │  6.9G │  11.1G │ [#######.............]  36.4% │ ext4 │ /dev/vda5  │
│ /boot/efi  │ 511.0M │  4.0K │ 511.0M │ [....................]   0.0% │ vfat │ /dev/vda1  │
│ /mnt/a     │   4.9G │ 20.0M │   4.6G │ [....................]   0.4% │ ext4 │ /dev/vdb1  │
│ /mnt/b     │   4.9G │ 20.0M │   4.6G │ [....................]   0.4% │ ext4 │ /dev/vdc1  │
╰────────────┴────────┴───────┴────────┴───────────────────────────────┴──────┴────────────╯
╭──────────────────────────────────────────────────────────────────────────────────────────────────╮
│ 7 special devices                                                                                │
├────────────────┬────────┬───────┬────────┬───────────────────────────────┬──────────┬────────────┤
│ MOUNTED ON     │   SIZE │  USED │  AVAIL │              USE%             │ TYPE     │ FILESYSTEM │
├────────────────┼────────┼───────┼────────┼───────────────────────────────┼──────────┼────────────┤
│ /dev           │   1.9G │    0B │   1.9G │                               │ devtmpfs │ udev       │
│ /dev/shm       │   1.9G │    0B │   1.9G │                               │ tmpfs    │ tmpfs      │
│ /run           │ 392.6M │  1.4M │ 391.2M │ [....................]   0.4% │ tmpfs    │ tmpfs      │
│ /run/lock      │   5.0M │  4.0K │   5.0M │ [....................]   0.1% │ tmpfs    │ tmpfs      │
│ /run/user/1000 │ 392.6M │  8.0K │ 392.6M │ [....................]   0.0% │ tmpfs    │ tmpfs      │
│ /run/user/1001 │ 392.6M │ 20.0K │ 392.6M │ [....................]   0.0% │ tmpfs    │ tmpfs      │
│ /sys/fs/cgroup │   1.9G │    0B │   1.9G │                               │ tmpfs    │ tmpfs      │
╰────────────────┴────────┴───────┴────────┴───────────────────────────────┴──────────┴────────────╯

As you can see under local devices, I now have /mnt/a and /mnt/b. Now that we know where they are mounted, lets check for that mount usage alone.

linuxman@ubuntu:~$ duf /mnt/a
╭───────────────────────────────────────────────────────────────────────────────────────╮
│ 1 local device                                                                        │
├────────────┬──────┬───────┬───────┬───────────────────────────────┬──────┬────────────┤
│ MOUNTED ON │ SIZE │  USED │ AVAIL │              USE%             │ TYPE │ FILESYSTEM │
├────────────┼──────┼───────┼───────┼───────────────────────────────┼──────┼────────────┤
│ /mnt/a     │ 4.9G │ 20.0M │  4.6G │ [....................]   0.4% │ ext4 │ /dev/vdb1  │
╰────────────┴──────┴───────┴───────┴───────────────────────────────┴──────┴────────────╯

Little note about duf is that it cannot be used to check disk usage of a directory/file. If you run duf on separate directories but they are part of the same filesystem, then the output will show the filesystem of both directories. It’s still kind of neat!

Checking Misc Mounts

What about loop devices? Thought I forgot about those didn’t ya? While I have not taken my memory pills in a while (swallows 3), I still remembered there is a way to check for other mount types on the system. If you have a disk image mounted or maybe (God forbid) a snap package mounted, you can check them by using the --all switch.

linuxman@ubuntu:~$ duf --all
╭─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ 14 local devices                                                                                                │
├──────────────────────────────┬────────┬────────┬────────┬───────────────────────────────┬──────────┬────────────┤
│ MOUNTED ON                   │   SIZE │   USED │  AVAIL │              USE%             │ TYPE     │ FILESYSTEM │
├──────────────────────────────┼────────┼────────┼────────┼───────────────────────────────┼──────────┼────────────┤
│ /                            │  19.1G │   6.9G │  11.1G │ [#######.............]  36.4% │ ext4     │ /dev/vda5  │
│ /boot/efi                    │ 511.0M │   4.0K │ 511.0M │ [....................]   0.0% │ vfat     │ /dev/vda1  │
│ /mnt/a                       │   4.9G │  20.0M │   4.6G │ [....................]   0.4% │ ext4     │ /dev/vdb1  │
│ /mnt/b                       │   4.9G │  20.0M │   4.6G │ [....................]   0.4% │ ext4     │ /dev/vdc1  │
│ /snap/bare/5                 │ 128.0K │ 128.0K │     0B │ [####################] 100.0% │ squashfs │ /dev/loop0 │
│ /snap/core20/1328            │  62.0M │  62.0M │     0B │ [####################] 100.0% │ squashfs │ /dev/loop1 │
│ /snap/core20/1518            │  62.0M │  62.0M │     0B │ [####################] 100.0% │ squashfs │ /dev/loop3 │
│ /snap/gnome-3-38-2004/106    │ 254.1M │ 254.1M │     0B │ [####################] 100.0% │ squashfs │ /dev/loop2 │
│ /snap/gnome-3-38-2004/99     │ 248.9M │ 248.9M │     0B │ [####################] 100.0% │ squashfs │ /dev/loop4 │
│ /snap/gtk-common-themes/1519 │  65.2M │  65.2M │     0B │ [####################] 100.0% │ squashfs │ /dev/loop5 │
│ /snap/gtk-common-themes/1534 │  81.4M │  81.4M │     0B │ [####################] 100.0% │ squashfs │ /dev/loop6 │
│ /snap/snap-store/558         │  54.2M │  54.2M │     0B │ [####################] 100.0% │ squashfs │ /dev/loop8 │
│ /snap/snapd/14978            │  43.6M │  43.6M │     0B │ [####################] 100.0% │ squashfs │ /dev/loop9 │
│ /snap/snapd/16010            │  47.0M │  47.0M │     0B │ [####################] 100.0% │ squashfs │ /dev/loop7 │
╰──────────────────────────────┴────────┴────────┴────────┴───────────────────────────────┴──────────┴────────────╯
╭─────────────────────────────────────────────────────────────────────────────────╮
│ 1 fuse device                                                                   │
├─────────────────────┬──────┬──────┬───────┬──────┬─────────────────┬────────────┤
│ MOUNTED ON          │ SIZE │ USED │ AVAIL │ USE% │ TYPE            │ FILESYSTEM │
├─────────────────────┼──────┼──────┼───────┼──────┼─────────────────┼────────────┤
│ /run/user/1000/gvfs │   0B │   0B │    0B │      │ fuse.gvfsd-fuse │ gvfsd-fuse │
╰─────────────────────┴──────┴──────┴───────┴──────┴─────────────────┴────────────╯
╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ 35 special devices                                                                                                    │
├─────────────────────────────────┬────────┬───────┬────────┬───────────────────────────────┬─────────────┬─────────────┤
│ MOUNTED ON                      │   SIZE │  USED │  AVAIL │              USE%             │ TYPE        │ FILESYSTEM  │
├─────────────────────────────────┼────────┼───────┼────────┼───────────────────────────────┼─────────────┼─────────────┤
│ /dev                            │   1.9G │    0B │   1.9G │                               │ devtmpfs    │ udev        │
│ /dev/hugepages                  │     0B │    0B │     0B │                               │ hugetlbfs   │ hugetlbfs   │
│ /dev/mqueue                     │     0B │    0B │     0B │                               │ mqueue      │ mqueue      │
│ /dev/pts                        │     0B │    0B │     0B │                               │ devpts      │ devpts      │
│ /dev/shm                        │   1.9G │    0B │   1.9G │                               │ tmpfs       │ tmpfs       │
│ /proc                           │     0B │    0B │     0B │                               │ proc        │ proc        │
│ /proc/sys/fs/binfmt_misc        │     0B │    0B │     0B │                               │ autofs      │ systemd-1   │
│ /proc/sys/fs/binfmt_misc        │     0B │    0B │     0B │                               │ binfmt_misc │ binfmt_misc │
│ /run                            │ 392.6M │  1.4M │ 391.2M │ [....................]   0.4% │ tmpfs       │ tmpfs       │
│ /run/lock                       │   5.0M │  4.0K │   5.0M │ [....................]   0.1% │ tmpfs       │ tmpfs       │
│ /run/user/1000                  │ 392.6M │  8.0K │ 392.6M │ [....................]   0.0% │ tmpfs       │ tmpfs       │
│ /run/user/1001                  │ 392.6M │ 20.0K │ 392.6M │ [....................]   0.0% │ tmpfs       │ tmpfs       │
│ /sys                            │     0B │    0B │     0B │                               │ sysfs       │ sysfs       │
│ /sys/fs/bpf                     │     0B │    0B │     0B │                               │ bpf         │ none        │
│ /sys/fs/cgroup                  │   1.9G │    0B │   1.9G │                               │ tmpfs       │ tmpfs       │
│ /sys/fs/cgroup/blkio            │     0B │    0B │     0B │                               │ cgroup      │ cgroup      │
│ /sys/fs/cgroup/cpu,cpuacct      │     0B │    0B │     0B │                               │ cgroup      │ cgroup      │
│ /sys/fs/cgroup/cpuset           │     0B │    0B │     0B │                               │ cgroup      │ cgroup      │
│ /sys/fs/cgroup/devices          │     0B │    0B │     0B │                               │ cgroup      │ cgroup      │
│ /sys/fs/cgroup/freezer          │     0B │    0B │     0B │                               │ cgroup      │ cgroup      │
│ /sys/fs/cgroup/hugetlb          │     0B │    0B │     0B │                               │ cgroup      │ cgroup      │
│ /sys/fs/cgroup/memory           │     0B │    0B │     0B │                               │ cgroup      │ cgroup      │
│ /sys/fs/cgroup/misc             │     0B │    0B │     0B │                               │ cgroup      │ cgroup      │
│ /sys/fs/cgroup/net_cls,net_prio │     0B │    0B │     0B │                               │ cgroup      │ cgroup      │
│ /sys/fs/cgroup/perf_event       │     0B │    0B │     0B │                               │ cgroup      │ cgroup      │
│ /sys/fs/cgroup/pids             │     0B │    0B │     0B │                               │ cgroup      │ cgroup      │
│ /sys/fs/cgroup/rdma             │     0B │    0B │     0B │                               │ cgroup      │ cgroup      │
│ /sys/fs/cgroup/systemd          │     0B │    0B │     0B │                               │ cgroup      │ cgroup      │
│ /sys/fs/cgroup/unified          │     0B │    0B │     0B │                               │ cgroup2     │ cgroup2     │
│ /sys/fs/fuse/connections        │     0B │    0B │     0B │                               │ fusectl     │ fusectl     │
│ /sys/fs/pstore                  │     0B │    0B │     0B │                               │ pstore      │ pstore      │
│ /sys/kernel/config              │     0B │    0B │     0B │                               │ configfs    │ configfs    │
│ /sys/kernel/debug               │     0B │    0B │     0B │                               │ debugfs     │ debugfs     │
│ /sys/kernel/security            │     0B │    0B │     0B │                               │ securityfs  │ securityfs  │
│ /sys/kernel/tracing             │     0B │    0B │     0B │                               │ tracefs     │ tracefs     │
╰─────────────────────────────────┴────────┴───────┴────────┴───────────────────────────────┴─────────────┴─────────────╯

So here we see that we have information about all kinds of mounted devices on our system which most of us probably don’t really care about. Still, its a nice-to-have kind of thing!

Checking Inodes

Wait… What are inodes in Linux? Inodes in the filesystem is where the metadata of the actual data is stored, but not the actual data. You can think of it as a database that indexes information about data, while the data is actually stored somewhere else. You index the database and know where to find the data, kind of like a map!

So how do we check for inodes? Well, simply by using the -inodes switch!

linuxman@ubuntu:~$ duf -inodes
╭─────────────────────────────────────────────────────────────────────────────────────────────╮
│ 4 local devices                                                                             │
├────────────┬─────────┬────────┬─────────┬───────────────────────────────┬──────┬────────────┤
│ MOUNTED ON │  INODES │  IUSED │  IAVAIL │             IUSE%             │ TYPE │ FILESYSTEM │
├────────────┼─────────┼────────┼─────────┼───────────────────────────────┼──────┼────────────┤
│ /          │ 1277952 │ 176606 │ 1101346 │ [##..................]  13.8% │ ext4 │ /dev/vda5  │
│ /boot/efi  │       0 │      0 │       0 │                               │ vfat │ /dev/vda1  │
│ /mnt/a     │  327680 │     11 │  327669 │ [....................]   0.0% │ ext4 │ /dev/vdb1  │
│ /mnt/b     │  327680 │     11 │  327669 │ [....................]   0.0% │ ext4 │ /dev/vdc1  │
╰────────────┴─────────┴────────┴─────────┴───────────────────────────────┴──────┴────────────╯
╭──────────────────────────────────────────────────────────────────────────────────────────────────╮
│ 7 special devices                                                                                │
├────────────────┬────────┬───────┬────────┬───────────────────────────────┬──────────┬────────────┤
│ MOUNTED ON     │ INODES │ IUSED │ IAVAIL │             IUSE%             │ TYPE     │ FILESYSTEM │
├────────────────┼────────┼───────┼────────┼───────────────────────────────┼──────────┼────────────┤
│ /dev           │ 493578 │   475 │ 493103 │ [....................]   0.1% │ devtmpfs │ udev       │
│ /dev/shm       │ 502549 │     1 │ 502548 │ [....................]   0.0% │ tmpfs    │ tmpfs      │
│ /run           │ 502549 │   846 │ 501703 │ [....................]   0.2% │ tmpfs    │ tmpfs      │
│ /run/lock      │ 502549 │     5 │ 502544 │ [....................]   0.0% │ tmpfs    │ tmpfs      │
│ /run/user/1000 │ 502549 │    39 │ 502510 │ [....................]   0.0% │ tmpfs    │ tmpfs      │
│ /run/user/1001 │ 502549 │    78 │ 502471 │ [....................]   0.0% │ tmpfs    │ tmpfs      │
│ /sys/fs/cgroup │ 502549 │    19 │ 502530 │ [....................]   0.0% │ tmpfs    │ tmpfs      │
╰────────────────┴────────┴───────┴────────┴───────────────────────────────┴──────────┴────────────╯

Now, as interesting as inodes are, we won’t be discussing them in detail here. However, from the output we can see our total available, used and remaining inodes on each mount/filesystem.

Filtering with DUF

Only Switches

What if you want to see only a certain type of device? Perhaps all of your snap mounts? We can do this using the switches -only, -only-mp, -only-fs. Lets first display only local devices.

linuxman@ubuntu:~$ duf -only local
╭──────────────────────────────────────────────────────────────────────────────────────────╮
│ 4 local devices                                                                          │
├────────────┬────────┬───────┬────────┬───────────────────────────────┬──────┬────────────┤
│ MOUNTED ON │   SIZE │  USED │  AVAIL │              USE%             │ TYPE │ FILESYSTEM │
├────────────┼────────┼───────┼────────┼───────────────────────────────┼──────┼────────────┤
│ /          │  19.1G │  6.9G │  11.1G │ [#######.............]  36.4% │ ext4 │ /dev/vda5  │
│ /boot/efi  │ 511.0M │  4.0K │ 511.0M │ [....................]   0.0% │ vfat │ /dev/vda1  │
│ /mnt/a     │   4.9G │ 20.0M │   4.6G │ [....................]   0.4% │ ext4 │ /dev/vdb1  │
│ /mnt/b     │   4.9G │ 20.0M │   4.6G │ [....................]   0.4% │ ext4 │ /dev/vdc1  │
╰────────────┴────────┴───────┴────────┴───────────────────────────────┴──────┴────────────╯

If we compare this to the default output, we see that only our local devices are displayed as expected.

Now let’s try filtering only mount points with a wildcard to list our snap mounts.

linuxman@ubuntu:~$ duf --all -only-mp '/snap/*'
╭────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ 10 local devices                                                                                               │
├──────────────────────────────┬────────┬────────┬───────┬───────────────────────────────┬──────────┬────────────┤
│ MOUNTED ON                   │   SIZE │   USED │ AVAIL │              USE%             │ TYPE     │ FILESYSTEM │
├──────────────────────────────┼────────┼────────┼───────┼───────────────────────────────┼──────────┼────────────┤
│ /snap/bare/5                 │ 128.0K │ 128.0K │    0B │ [####################] 100.0% │ squashfs │ /dev/loop0 │
│ /snap/core20/1328            │  62.0M │  62.0M │    0B │ [####################] 100.0% │ squashfs │ /dev/loop1 │
│ /snap/core20/1518            │  62.0M │  62.0M │    0B │ [####################] 100.0% │ squashfs │ /dev/loop3 │
│ /snap/gnome-3-38-2004/106    │ 254.1M │ 254.1M │    0B │ [####################] 100.0% │ squashfs │ /dev/loop2 │
│ /snap/gnome-3-38-2004/99     │ 248.9M │ 248.9M │    0B │ [####################] 100.0% │ squashfs │ /dev/loop4 │
│ /snap/gtk-common-themes/1519 │  65.2M │  65.2M │    0B │ [####################] 100.0% │ squashfs │ /dev/loop5 │
│ /snap/gtk-common-themes/1534 │  81.4M │  81.4M │    0B │ [####################] 100.0% │ squashfs │ /dev/loop6 │
│ /snap/snap-store/558         │  54.2M │  54.2M │    0B │ [####################] 100.0% │ squashfs │ /dev/loop8 │
│ /snap/snapd/14978            │  43.6M │  43.6M │    0B │ [####################] 100.0% │ squashfs │ /dev/loop9 │
│ /snap/snapd/16010            │  47.0M │  47.0M │    0B │ [####################] 100.0% │ squashfs │ /dev/loop7 │
╰──────────────────────────────┴────────┴────────┴───────┴───────────────────────────────┴───────


This post first appeared on Linuxman Tech, please read the originial post: here

Share the post

EASILY View Disk Usage in Linux with DUF

×

Subscribe to Linuxman Tech

Get updates delivered right to your inbox!

Thank you for your subscription

×