Hard drives, SSDs, flash drives, SD cards and so on. All storage solutions that will, sooner or later, run out of space. When they do, you will probably ask yourself where did all the space go?
To answer that question you can use a disk usage viewing tool. There are various third party commercial tools that you can use, but if you’re running Linux or macOS you can take advantege of the terminal which comes with built-in tools or use third party free and open source tools.
ALSO READ HOW TO: Create Time-Saving Aliases
1. Using du and df
These are two standard Unix programs that complement eachother. du
stands for disk usage
and df
stands for disk free
.
To use these commands, you can execute them as is (i.e du
or df
) or read the manual with man df
and man du
to see all the options.
2. Using dust
Dust is, as the developer puts it, like du
but more intuitive. Dust is meant to give you an instant overview of which directories are using disk space without requiring sort or head.
Install dust:
- Linux:
cargo install du-dust
or download binary ( Arch users can find dust in AUR ) - macOS: using Homebrew.
brew install dust
or download binary - Windows: download binary ( NOTE: I’m not sure how the Windows binary works. I don’t have any Windows machines, not even a VM )
Usage:
dust <dir>
dust <dir> <another_dir> <and_more>
dust -p <dir> (full-path - does not shorten the path of the subdirectories)
dust -s <dir> (apparent-size - shows the length of the file as opposed to the amount of disk space it uses)
dust -n 30 <dir> (shows 30 directories instead of the default)
dust -d 3 <dir> (shows 3 levels of subdirectories)
dust -r <dir> (reverse order of output, with root at the lowest)
dust -x <dir> (only show directories on the same filesystem)
dust -X ignore <dir> (ignore all files and directories with the name 'ignore')
dust -b <dir> (do not show percentages or draw ASCII bars)
3. DUC – Dude, where are my bytes
Duc is a collection of tools for indexing, inspecting and visualizing disk usage. Duc maintains a database of accumulated sizes of directories of the file system, and allows you to query this database with some tools, or create fancy graphs showing you where your bytes are.
Install DUC:
- Linux: on Debian/Ubuntu based systems use
sudo apt install duc
. Arch users can find duc in AUR. Everybody else can compile it from the source code. - macOS: using Homebrew.
brew install duc
Usage:
Duc comes with a command line tool called duc, which is used to create, maintain and query the disk usage database. To see a list of available commands run duc help
or run man duc
for an extensive documentation.
First you need to index a directory you want to run duc against. It can be /
, /usr
or /home/username
. This will create a database on ~/.duc.db
.
NOTE: macOS users will have to index /Users/username
instead of /home/username
and I see no point in indexing just /usr
Once the desired directory is indexed, you can list all files and directories , showing relative file sizes in a graph with duc ls -Fg /indexed/directory
However, duc comes with an UI and a GUI interface. Which makes duc even more useful. To show the UI interface you will need to run duc ui /indexed/directory
. This will return the ncurses console interaface which can be navigated with the keyboard.
To start the graphical interface and explore the filesystem using a sunburst graph run duc gui /indexed/directory
. This interface can be navigated with the mouse ( scroll to zoom in and out, and click to select ).