Using Dua (Disk Usage Analyzer) Command (with examples)
Analyzing a Specific Directory
To analyze a specific directory, you can use the dua
command followed by the path to the directory you want to analyze.
dua path/to/directory
Motivation: Analyzing disk usage is essential for managing storage resources effectively. By analyzing a specific directory, you can identify which files and subdirectories consume the most space, helping you make informed decisions about storage optimization.
Explanation:
dua
- invokes the Dua command.path/to/directory
- specifies the path to the directory you want to analyze.
Example Output:
📂 /path/to/directory
40.3 KB file1.txt
954.2 MB file2.csv
13.6 GB subdirectory
13.6 GB Total
Displaying Apparent Size
By default, Dua displays disk usage. However, you can use the --apparent-size
flag to display the apparent size instead.
dua --apparent-size
Motivation: Apparent size represents the actual size of a file or directory when stored on the disk. It accounts for the space used by sparse files or compressed data. Displaying the apparent size provides a more accurate representation of storage consumption.
Explanation:
--apparent-size
- enables displaying the apparent size instead of disk usage.
Example Output:
📂 /path/to/directory
40.3 KB file1.txt
1.0 GB file2.csv
13.6 GB subdirectory
13.6 GB Total
Counting Hard-Linked Files
To count hard-linked files each time they are seen, you can use the --count-hard-links
flag.
dua --count-hard-links
Motivation: Hard links are multiple references to the same file on the filesystem. Counting hard-linked files individually helps you understand the true impact of these files on your disk usage.
Explanation:
--count-hard-links
- enables counting hard-linked files each time they are encountered.
Example Output:
📂 /path/to/directory
40.3 KB file1.txt
954.2 MB file2.csv
13.6 GB subdirectory
2.3 GB hard_linked_file.txt
16.2 GB Total
Aggregating Space Usage
To aggregate the consumed space of one or more directories or files, you can use the dua aggregate
command.
dua aggregate
Motivation:
The dua aggregate
command allows you to combine the disk usage information from multiple directories or files into a single summary. This can be useful for analyzing the overall storage consumption of a specific set of directories or files.
Explanation:
aggregate
- command to aggregate disk space usage.
Example Output:
📂 /path/to/directory1
100.0 MB file1.txt
📂 /path/to/directory2
200.0 MB file2.txt
📂 /path/to/directory3
300.0 MB file3.txt
600.0 MB Total
Launching the Terminal User Interface
To launch Dua’s terminal user interface, you can use the dua interactive
command.
dua interactive
Motivation: The terminal user interface (TUI) provides an interactive way to explore disk usage information. It allows you to navigate through directories, view detailed file sizes, and interactively analyze your storage resources.
Explanation:
interactive
- command to launch the terminal user interface.
Example Output:
📂 /
40.3 KB home/
954.2 MB var/
13.6 GB etc/
14.6 GB Total
â–¶ Press Enter to view home directory
Formatting Byte Counts
Dua allows you to format the printing of byte counts using different units. You can use the --format
flag followed by the desired format.
dua --format metric|binary|bytes|GB|GiB|MB|MiB
Motivation: Formatting byte counts in different units helps in presenting disk usage information in a user-friendly way. It allows you to choose the most suitable unit for your specific needs, whether it’s using metric prefixes (e.g., GB), binary prefixes (e.g., GiB), or displaying raw bytes.
Explanation:
--format
- enables specifying the desired format for byte counts.metric
- displays byte counts using metric prefixes (e.g., KB, MB, GB).binary
- displays byte counts using binary prefixes (e.g., KiB, MiB, GiB).bytes
- displays byte counts without any unit.GB
- displays byte counts in gigabytes.GiB
- displays byte counts in gibibytes.MB
- displays byte counts in megabytes.MiB
- displays byte counts in mebibytes.
Example Output:
📂 /path/to/directory
40.3 KB file1.txt
954.2 MB file2.csv
13.6 GB subdirectory
13.6 GB Total
Setting the Number of Threads
To set the number of threads used by Dua for analyzing disk space, you can use the --threads
flag followed by the desired count.
dua --threads count
Motivation: By default, Dua utilizes multiple threads to speed up disk usage analysis. However, in some cases, limiting the number of threads can be beneficial, especially if the system has limited resources or if you want to prioritize other tasks running concurrently.
Explanation:
--threads
- enables setting the number of threads used.count
- specifies the desired number of threads.
Example Output:
📂 /path/to/directory
40.3 KB file1.txt
954.2 MB file2.csv
13.6 GB subdirectory
13.6 GB Total
Conclusion
In this article, we explored various use cases of the Dua (Disk Usage Analyzer) command. We discussed how to analyze specific directories, display apparent size, count hard-linked files, aggregate space usage, launch the terminal user interface, format byte counts, and set the number of threads. These examples demonstrate the flexibility and versatility of the Dua command, empowering users to efficiently manage disk space and optimize storage resources.