Linux Commands

How to Use Duf Command in Linux

This article will cover a guide on using the “duf” command in Linux. Duf is a free and open source command line utility that can show resource usage and free space available on local or remote storage devices connected to a Linux system. It is an advanced and more user friendly version of another such command line utility called “df”, which is available by default in all major Linux distributions.

Main features of Duf Command

The main features of the duf command line utility includes:

  • Ability to present data in tabular layout.
  • Ability to show colored output for improved readability.
  • Classifies data into different groups according to the type of the storage device.
  • Support sorting of displayed results.
  • Supports automatic resizing of terminal window matching the size of output data.
  • Ability to hide output for certain storage types.
  • Supports presenting data in JSON format (can be exported to an external file).

Installing Duf Command in Linux

Duf command can be installed in Ubuntu from the snap store. To do so, run the command specified below in a terminal:

$ sudo snap install duf-utility

Duf may be available in repositories of your Linux distribution. So you can search for it in the package manager and install it from there. More distribution specific packages and installation instructions are available here.

View Disk Usage Information About All Devices and Filesystems

To show tabular data about used and free space on local or remote storage drives, simply run the following command:

$ duf

Depending on storage disks connected on your system, you should get some output similar to this:

Hide Information About Specific Filesystems

You can hide specific filesystem types by using “-hide-fs” switch and supplying it a filesystem type as an argument. Here is an example command:

$ duf -hide-fs squashfs

The command above will hide all filesystem entries having “squashfs” as the type.

You can use multiple comma separated values as arguments in the command.

View Information About Specific Filesystem Types Only


You can use the “-only-fs” command line option to view information about specific filesystem types only and hide everything else. Here is an example command:

$ duf -only-fs ext4

You can use multiple comma separated values as arguments in the command. This option is opposite of the “hide-fs” command line switch explained above.

Hide Entire Device Type Categories or Specific Device Types

If you want to hide an entire device type category, you can use the “-hide” switch and add a category type as an argument. For instance to hide all “special” type devices, run a command in the following format:

$ duf -hide special

You can use the same command to hide specific device types. For instance to hide “loop” mounted devices, run a command in the following format:

$ duf -hide loops

The “-hide” switch takes “network”, “special”, “local”, “loops”, “fuse”, and “binds” as possible values. You can use multiple comma separated values as arguments in the command.

View Information about Specific Device Types Only

If you want to view usage information about a few particular device types only, use the “-only” switch. This command is the opposite of the “-hide” switch mentioned above.

$ duf -only local

The “-only” switch takes “network”, “special”, “local”, “loops”, “fuse”, and “binds” as possible values. You can use multiple comma separated values as arguments in the command.

Sort Output Using Specific Columns

You can sort the disk usage output using the heading of a specific column type by using “-sort” command line switch. For instance, to sort the tabular data using size, run a command in the following format:

$ duf -sort size

The “-sort”  command line option takes “size”, “used”, “mountpoint”, “avail” and other such column headings as possible arguments. Full list of possible arguments can be found on the man page.

View Usage in JSON Format and Export Data to a File

To view disk usage data in JSON format, use the “-json” switch”.

$ duf -json

To export JSON data to a file, run a command in the following format (replace filename as needed):

$ duf -json > usage.json

Further Help on the Duf Command

After installing the duf command command, you can run the following command to know more about its usage options.

$ duf --help

You can also check the duf man page available here.

Conclusion

The duf command has some additional options over the traditional df command included by default in most Linux distributions. Its tabular data representation and inclusion of more filesystem types provides a much better understanding of disk usage patterns on your Linux system.

About the author

Nitesh Kumar

I am a freelancer software developer and content writer who loves Linux, open source software and the free software community.