How to use the command "dust" (with examples)
Dust is a command-line tool that provides an instant overview of which directories are using disk space. It is useful for identifying which directories are taking up the most space on your system, allowing you to make informed decisions about cleaning up or organizing your files.
Use case 1: Display information for the current directory
Code:
dust
Motivation: By running the “dust” command without any arguments, you can quickly see the disk space usage for the current directory. This is helpful in understanding how much space is being occupied by the files and directories in your current location.
Explanation: When running “dust” without any arguments, it displays information about the disk space usage for the current directory.
Example output:
Home
├── Documents (10.0 MB)
├── Pictures (25.0 MB)
├── Music (40.0 MB)
├── Downloads (5.0 MB)
└── Desktop (15.0 MB)
Total disk usage: 95.0 MB
Use case 2: Display information for a space-separated list of directories
Code:
dust path/to/directory1 path/to/directory2
Motivation: Sometimes, you may want to analyze the disk space usage of specific directories in your system. By providing a space-separated list of directories as arguments, you can obtain information about the disk space usage of those directories.
Explanation: By specifying the paths of the directories you want to analyze as space-separated arguments, you can view the disk space usage information for those directories.
Example output:
Directory1
├── Subdirectory1 (10.0 MB)
├── Subdirectory2 (15.0 MB)
└── Subdirectory3 (5.0 MB)
Directory2
├── Subdirectory1 (20.0 MB)
├── Subdirectory2 (5.0 MB)
└── Subdirectory3 (10.0 MB)
Total disk usage: 65.0 MB
Use case 3: Display 30 directories (defaults to 21)
Code:
dust --number-of-lines 30
Motivation: By default, “dust” displays information for the 21 directories with the largest disk space usage. However, you may want to see information for a larger number of directories. By using the “–number-of-lines” option, you can specify the desired number of directories to be displayed.
Explanation: When using the “–number-of-lines” option, you can specify the number of directories to be displayed. In this example, by setting it to 30, “dust” will provide information for the 30 directories with the largest disk space usage.
Example output:
Directory1 (100.0 MB)
├── Subdirectory1 (30.0 MB)
├── Subdirectory2 (20.0 MB)
├── Subdirectory3 (15.0 MB)
└── ...
Directory2 (80.0 MB)
├── Subdirectory1 (40.0 MB)
├── Subdirectory2 (20.0 MB)
├── Subdirectory3 (10.0 MB)
└── ...
...
Total disk usage: 1000.0 MB
Use case 4: Display information for the current directory, up to 3 levels deep
Code:
dust --depth 3
Motivation: By default, “dust” displays information without any depth limitation, showing the complete directory structure. However, you may want to limit the depth of the information displayed to a specific number of levels. This is useful when you only need an overview of the storage usage without going into too much detail.
Explanation: The “–depth” option allows you to specify the maximum depth of the directory tree to be displayed. In this example, by setting it to 3, “dust” will provide information for the current directory and its immediate subdirectories up to three levels deep.
Example output:
Home
├── Documents (10.0 MB)
│ ├── Folder1 (5.0 MB)
│ │ ├── Subfolder1 (3.0 MB)
│ │ └── Subfolder2 (2.0 MB)
│ └── Folder2 (5.0 MB)
├── Pictures (25.0 MB)
│ ├── Vacation (15.0 MB)
│ │ └── Beach (10.0 MB)
│ └── Family (10.0 MB)
└── Music (40.0 MB)
Total disk usage: 75.0 MB
Use case 5: Display the biggest directories at the top in descending order
Code:
dust --reverse
Motivation: By default, “dust” displays directories in ascending order based on their size. However, you may want to have the biggest directories displayed first, making it easier to identify the largest contributors to disk space usage.
Explanation: The “–reverse” option causes “dust” to sort directories in descending order based on their size. This way, the directories with the largest disk space usage will appear at the top of the output.
Example output:
Directory1 (100.0 MB)
├── Subdirectory1 (30.0 MB)
├── Subdirectory2 (20.0 MB)
├── Subdirectory3 (15.0 MB)
└── ...
Directory2 (80.0 MB)
├── Subdirectory1 (40.0 MB)
├── Subdirectory2 (20.0 MB)
├── Subdirectory3 (10.0 MB)
└── ...
...
Total disk usage: 1000.0 MB
Use case 6: Ignore all files and directories with a specific name
Code:
dust --ignore-directory file_or_directory_name
Motivation: In some cases, you may want to exclude specific files or directories from the disk space analysis, as they are not relevant to your current task or investigation. By using the “–ignore-directory” option, you can specify a name to ignore.
Explanation: The “–ignore-directory” option allows you to exclude files or directories from the disk space analysis based on their name. In this example, by specifying the name “file_or_directory_name”, “dust” will ignore all files and directories with that name.
Example output:
Directory1 (100.0 MB)
├── Subdirectory1 (30.0 MB)
├── Subdirectory2 (20.0 MB)
├── Subdirectory3 (15.0 MB)
└── ...
Directory2 (80.0 MB)
├── Subdirectory1 (40.0 MB)
├── Subdirectory2 (20.0 MB)
├── Subdirectory3 (10.0 MB)
└── ...
...
Total disk usage: 800.0 MB
Use case 7: Do not display percent bars and percentages
Code:
dust --no-percent-bars
Motivation: By default, “dust” displays percent bars and percentages next to each directory to provide a visual representation of their disk space usage. However, you may prefer to disable these visual elements if you are only interested in the numerical values.
Explanation: The “–no-percent-bars” option removes the percent bars and percentages from the output of “dust”. This way, only the numerical values indicating the disk space usage will be shown.
Example output:
Directory1 (100.0 MB)
├── Subdirectory1 (30.0 MB)
├── Subdirectory2 (20.0 MB)
├── Subdirectory3 (15.0 MB)
└── ...
Directory2 (80.0 MB)
├── Subdirectory1 (40.0 MB)
├── Subdirectory2 (20.0 MB)
├── Subdirectory3 (10.0 MB)
└── ...
...
Total disk usage: 1000.0 MB
Conclusion:
The “dust” command is a powerful tool for quickly understanding disk space usage in your system. By using the various available options, such as specifying directories, adjusting the number of directories displayed, limiting the depth, or customizing the output format, you can gain valuable insights into the storage allocation of your files and directories. Whether you are investigating storage issues, organizing your files, or simply curious about which directories are using the most space, “dust” provides a convenient and informative overview.