Using 'gdu' for Disk Usage Analysis (with examples)

Using 'gdu' for Disk Usage Analysis (with examples)

Gdu (Go Disk Usage) is a robust tool designed to analyze disk usage through a console interface, enabling users to easily understand their disk consumption. It shines in scenarios where disk management becomes paramount, offering interactive segmentation of disk space consumption. With various options and settings, users can customize their views to match specific criteria, making it versatile for myriad use cases.

Use case 1: Interactively show the disk usage of the current directory

Code:

gdu

Motivation:

Understanding how disk space is utilized within the current directory is crucial for maintaining optimal storage use. By employing gdu, users can determine which files or subdirectories are consuming the most space, making it easier to perform clean-up operations or storage optimization.

Explanation:

  • gdu: This command, when used without any additional arguments, targets the current directory. The interactive mode allows users to delve into every subdirectory and file, providing a clear, hierarchical view of disk usage.

Example Output:

Total disk usage: 3.4 GB
-----------------------------
Path                          Size
/home/user/documents          1.2 GB
/home/user/downloads          800 MB
/home/user/music              1.4 GB

Use case 2: Interactively show the disk usage of a given directory

Code:

gdu path/to/directory

Motivation:

When the focus is on a specific directory rather than the default current one, pointing gdu to this directory helps in assessing storage consumption within that directory, again aiding cleanup and decision-making regarding file storage.

Explanation:

  • gdu: Calls the Go Disk Usage tool.
  • path/to/directory: Directs gdu to analyze this specified path instead of the current working directory, providing insights specific to that directory.

Example Output:

Total disk usage: 5.6 GB
-----------------------------
Path                          Size
/path/to/directory/photos     3.0 GB
/path/to/directory/videos     2.6 GB

Use case 3: Interactively show the disk usage of all mounted disks

Code:

gdu --show-disks

Motivation:

For users managing multiple disks or platforms that include several mounted drives, gdu provides a consolidated view of disk usage across all mounted disks. This can be particularly useful for system administrators needing a broad overview of space usage.

Explanation:

  • --show-disks: This flag instructs gdu to gather data from all mounted disks, expanding its reach beyond just a single directory or filesystem.

Example Output:

Mount Point                  Total Size    Used    Available    Use%
/                            256 GB        200 GB   56 GB        78%
/mnt/data                    1 TB          700 GB   300 GB       70%
/mnt/backup                  500 GB        450 GB   50 GB        90%

Use case 4: Interactively show the disk usage of the current directory but ignore some sub-directories

Code:

gdu --ignore-dirs path/to/directory1,path/to/directory2,...

Motivation:

Certain directories might not be relevant for a current analysis, such as those frequently cleaned or those not meant for scrutiny due to their nature (e.g., backup folders). Ignoring these can yield a cleaner and more focused analysis.

Explanation:

  • --ignore-dirs: Tells gdu to exclude specified directories from the analysis. Multiple directories are enumerated by separating paths with commas.

Example Output:

Total disk usage: 2.2 GB (excluding specified directories)
-----------------------------
Path                          Size
/home/user/documents          1.1 GB
/home/user/music              1.1 GB

Use case 5: Ignore paths by regular expression

Code:

gdu --ignore-dirs-pattern '.*[abc]+'

Motivation:

For users with numerous directories and files, employing a regular expression to filter paths can help bypass large numbers of irrelevant files, focusing only on specific patterns of interest.

Explanation:

  • --ignore-dirs-pattern: This option allows users to input a regular expression to match directories to be ignored, adding a layer of flexibility and precision to the disk analysis.

Example Output:

Total disk usage: 3.0 GB (excluding regex-matched directories)
-----------------------------
Path                          Size
/home/user/music              1.5 GB
/home/user/videos             1.5 GB

Use case 6: Ignore hidden directories

Code:

gdu --no-hidden

Motivation:

Hidden directories often contain configuration files and caches that might not be necessary to include in a general disk usage overview. Ignoring them helps focus on user-created or user-important files.

Explanation:

  • --no-hidden: Instructs gdu to skip over directories and files typically hidden (those starting with a dot), prioritizing visible and more relevant data.

Example Output:

Total disk usage: 4.0 GB (excluding hidden directories)
-----------------------------
Path                          Size
/home/user/documents          2.0 GB
/home/user/videos             2.0 GB

Use case 7: Only print the result, do not enter interactive mode

Code:

gdu --non-interactive path/to/directory

Motivation:

Sometimes, users require a quick summary without interaction, maybe for reports or rapid checks. gdu can accommodate this need by simply outputting the disk usage information without further exploration.

Explanation:

  • --non-interactive: Switches gdu to a mode where it calculates and prints results directly in the console rather than providing an interactive browsing option.

Example Output:

Total disk usage: 7.8 GB
/path/to/directory            7.8 GB

Use case 8: Do not show the progress in non-interactive mode (useful in scripts)

Code:

gdu --no-progress path/to/directory

Motivation:

When integrating gdu into scripts, especially in environments where you want to minimize output clutter or logs, not displaying progress helps keep script logs clean and efficient.

Explanation:

  • --no-progress: Suppresses any progress indicators during the analysis, which is useful when gdu is part of automated workflows where progress output is unnecessary.

Example Output:

Total disk usage: 10.5 GB
/path/to/directory            10.5 GB

Conclusion:

Gdu is a powerful utility for disk space analysis, with versatility evident in its plethora of options. Whether for interactive exploration or script-based tasks, it provides precise control over disk usage metrics, adaptable to various needs in both personal and professional settings. Through strategic use of its options, users can achieve a clearer understanding of their storage consumption, aiding in efficient disk management.

Related Posts

How to Use the Command 'netstat' (with Examples)

How to Use the Command 'netstat' (with Examples)

The netstat command is a powerful utility in Unix-like operating systems that displays network-related information such as open connections, routing tables, interface statistics, masquerade connections, and multicast memberships.

Read More
How to use the command 'git feature' (with examples)

How to use the command 'git feature' (with examples)

The git feature command is part of the Git Extras toolkit, which enhances Git’s core capabilities by providing convenient shortcuts for common tasks.

Read More
How to Use the Command 'Rector' (with Examples)

How to Use the Command 'Rector' (with Examples)

Rector is a powerful tool used for automated updating and refactoring of PHP code from version 5.

Read More