How to Use the Command 'duf' (with Examples)
The duf
command is a convenient disk usage and free space utility designed to provide users with a more user-friendly representation of disk capacity, usage, and availability compared to traditional disk space tools like df
. This tool offers a colorful and well-structured output that makes the reading of disk statistics more intuitive. duf
not only highlights critical values such as used and available disk space but also presents this information in a way that is easy to digest, perfect for users who need to monitor disk usage over multiple devices or file systems.
Use Case 1: List Accessible Devices
Code:
duf
Motivation:
Running duf
without any arguments provides a quick summary of all the accessible storage devices connected to your system. It’s particularly useful when you want an at-a-glance look at your storage consumption and capacity across different devices without needing to delve into technical details.
Explanation:
This command, when executed, runs duf
in its default mode. It scans for all devices currently accessible and provides details about them in a clean and organized terminal display. By omitting additional flags, duf
focuses solely on showing mounted devices, which often suffices for regular disk monitoring needs.
Example Output:
MOUNTPOINT SIZE USED AVAIL USE% TYPE FILESYSTEM
/dev/sda1 250G 80G 170G 32% ext4 /dev/sda1
/dev/sdb1 500G 450G 50G 90% ntfs /dev/sdb1
This output shows that two file systems are mounted, with relevant details about their total size, used space, available space, and percentage usage.
Use Case 2: List Everything Including Pseudo and Duplicate File Systems
Code:
duf --all
Motivation:
Sometimes, you might require a more comprehensive overview of all mounted file systems, including those that are typically hidden such as pseudo, inaccessible, or duplicate file systems. This option is valuable for advanced diagnostics or systems analysis.
Explanation:
Here, the --all
flag is used. This flag instructs duf
to ignore the usual filtering that hides less useful or duplicate entries and, instead, list everything it detects. It expands the displayed information to include every file system the tool can access, which is essential when a thorough disk usage audit is required.
Example Output:
MOUNTPOINT SIZE USED AVAIL USE% TYPE FILESYSTEM
/dev/sda1 250G 80G 170G 32% ext4 /dev/sda1
tmpfs 5.0M 0 5.0M 0% tmpfs tmpfs
/dev/sdb1 500G 450G 50G 90% ntfs /dev/sdb1
/dev/loop0 4.2G 4.2G 0 100% squashfs /dev/loop0
Here, not only regular storage devices but also temporary file systems like tmpfs
and loopback devices such as squashfs
are shown.
Use Case 3: Show Specific Devices or Mount Points
Code:
duf /path/to/directory1 /path/to/directory2
Motivation:
This use case is great when you’re interested in checking the disk usage for specific directories or mount points. This targeted approach helps you focus on critical aspects of your storage without getting overwhelmed with too much information.
Explanation:
By specifying paths directly after the duf
command, you instruct it to display information only for these specified directories or mount points. This capability is extremely beneficial for quickly assessing the condition of select locations without sorting through unnecessary data.
Example Output:
MOUNTPOINT SIZE USED AVAIL USE% TYPE FILESYSTEM
/path/to/directory1 100G 30G 70G 30% ext4 /dev/sda2
/path/to/directory2 200G 150G 50G 75% xfs /dev/sdc1
This output displays the storage statistics for just the requested paths, making the review precise and relevant.
Use Case 4: Sort the Output by Specific Criteria
Code:
duf --sort size
Motivation:
Sorting the output facilitates better order and readability when analyzing disk usage, especially when dealing with multiple devices or directories. Using sorting criteria, you can, for instance, focus on the most full or largest devices first.
Explanation:
The --sort
flag followed by a criteria keyword such as size
, used
, avail
, or usage
lets users sort the list according to their specific interests. This kind of sorting is integral for tailored disk analysis, helping prioritize actions based on the disk usage status.
Example Output:
MOUNTPOINT SIZE USED AVAIL USE% TYPE FILESYSTEM
/dev/sdb1 2T 1.5T 500G 75% ext4 /dev/sdb1
/dev/sda1 250G 80G 170G 32% ext4 /dev/sda1
Here, devices are listed by their total capacity in descending order, assisting in identifying the largest storage resources at a glance.
Use Case 5: Show or Hide Specific File Systems
Code:
duf --only-fs tmpfs
Motivation:
Isolating or excluding certain types of file systems can help cut through the clutter when examining disk statistics on complex systems with multiple storage management formats. This function is crucial for focused disk diagnostics and verification tasks across homogeneous storage types.
Explanation:
Using the --only-fs
flag allows the display of only file systems matching the specified type, here tmpfs
. Conversely, --hide-fs
followed by a file system type would do the opposite. This feature is particularly advantageous when interest is restricted to certain variable file systems, like temporary or network file systems.
Example Output:
MOUNTPOINT SIZE USED AVAIL USE% TYPE FILESYSTEM
tmpfs 5.0M 0 5.0M 0% tmpfs tmpfs
In this scenario, the output shows only tmpfs
types, helping narrow focus to accessible temporary storage spaces.
Use Case 6: Sort Output by Key
Code:
duf --sort mountpoint
Motivation:
Sorting by specific keys such as mountpoint
or filesystem
can streamline data examination by organizing entries alphabetically or logically. This is beneficial for cross-referencing with other data organized in similar orders.
Explanation:
The --sort
flag allows specifying the sort key, enabling users to arrange the output based on the criteria that matter most to them, such as mountpoint
, type
, or filesystem
, among others. This precise sorting is central to structuring and correlating data efficiently in broader analyses.
Example Output:
MOUNTPOINT SIZE USED AVAIL USE% TYPE FILESYSTEM
/path/to/directory2 200G 150G 50G 75% xfs /dev/sdc1
/path/to/directory1 100G 30G 70G 30% ext4 /dev/sda2
Here data is collated by the mountpoint name, aiding in location-based resource assessment.
Use Case 7: Change the Theme
Code:
duf --theme dark
Motivation:
Switching themes can enhance visibility or readability based on user preference and terminal configuration. This makes data presentation pleasant and reduces eye strain, especially over long durations of disk monitoring.
Explanation:
By using the --theme
flag followed by either dark
or light
, you toggle the display aesthetics to better fit your working environment or personal comfort. This functionality is invaluable for adapting the tool to varied lighting conditions or personal preferences to maintain optimal ergonomics.
Example Output:
The example output remains functionally consistent in terms of information, but visual adjustments make numbers, headers, and separators more prominent or subtle based on the theme chosen, improving comprehension or comfort according to color scheme compatibility.
Conclusion:
The duf
command is an invaluable tool for managing and analyzing disk usage and availability with a range of configurable options tailored to different needs. Its versatility lies in its ability to adapt its output to diverse analytical contexts, making it suitable for both simple checks and advanced monitoring tasks through concise, colored presentations and flexible sorting options. Understanding and leveraging these capabilities can greatly enhance your efficiency in disk management and server maintenance tasks.