Skip to content

Instantly share code, notes, and snippets.

@alexrutar
Last active July 11, 2023 09:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexrutar/28b7de23a894ad936647258d18091b6a to your computer and use it in GitHub Desktop.
Save alexrutar/28b7de23a894ad936647258d18091b6a to your computer and use it in GitHub Desktop.
Get the largest files in a directory in human-readable format.

If you have a folder my/folder, you can run

du -h my/folder | sort -rh | head -n 10

to get a list of the 10 largest subfolders.

Explanation:

  • du -h: get the size of the elements in the folder in human-readable format
  • sort -rh: sort human-readable in reverse order (requires an updated version of sort)
  • head -n 10: only take the first 10 elements

The tree command also has built in support for showing file sizes: run tree --du and the file sizes will be included in the directory listing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment