« Back to File systems: Frequently Asked Questions

How to find the biggest directories on disk

How to find the biggest directories on the disk?

Run the du command and filter the output using sort.

du -ahx / | sort -hr | head

Looking to clean up some data, but unclear what the biggest directories are on the disk or within a partition? In this FAQ we look at how to quickly find them.

Find biggest directories

With the du command we can count the disk usage of directories. By using the --all option, it will combine the size of both files and underlying directories.

There is also the option --one-file-system, which will count only directories and files on the same file system. This is useful when there are external mounts. For example when using NFS, we don’t want to scan the full NAS as well.

du --all --one-file-system /

Want to use the shortened options and sort the output? Use sort to do the sorting and head to only show 10 results.

du -a -x / | sort -n -r | head

Combine the options of the commands to make them even shorter.

du -ax | sort -nr | head

Making it human-readable

The output can be a bit friendlier by using human-readable output. In that case, we need to tell both du and sort to change the default output style.

du --all --human-readable --one-file-system / | sort --human-numeric-sort --reverse | head

Want to use the shortened options for this command as well?

du -ahx / | sort -hr | head

Relevant commands in this article

Like to learn more about the commands that were used in this article? Have a look, for some there is also a cheat sheet available.

  • ducheat sheet
  • head
  • sort

Other questions related to Linux file systems

    Related articles

    Like to learn more? Here is a list of articles within the same category or having similar tags.

    Feedback

    Small picture of Michael Boelen

    This article has been written by our Linux security expert Michael Boelen. With focus on creating high-quality articles and relevant examples, he wants to improve the field of Linux security. No more web full of copy-pasted blog posts.

    Discovered outdated information or have a question? Share your thoughts. Thanks for your contribution!

    Mastodon icon