Check Which Folders or Files are Using the Highest Disk Space (Linux, macOS, BSD)

If your disk is almost full and you want to track down where the disk space is going, i.e., which files or folders are occupying the most or maximum amount of space then you can start with using the du (disk usage) utility to which you’ll have to pass a couple of options:

$ du -ah -d 1 2>/dev/null /home/codingshower | sort -hr

The different options passed to du and sort in the command above is explained here.

Although du works just fine, my primary aim in this article is to share the ncdu utility which displays the list of files and folders sorted by disk usage size (descending order) in your terminal, in a nice text-based user interface. From the manual:

ncdu (NCurses Disk Usage) is a curses-based version of the well-known ‘du’, and provides a fast way to see what directories are using your disk space.

Just install the ncdu utility with your favourite package manager:

$ brew install ncdu # macOS
$ apt install ncdu # Ubuntu, Debian
$ dnf install ncdu # CentOS, Fedora
$ pkg install ncdu # FreeBSD

And then hit ncdu in the command line:

$ ncdu

You should see a nice interface like this:

ncdu interface

You can pass whatever directory you like to the command – ncdu /path/to/directory.

Leave a Reply

Your email address will not be published.