Created
July 8, 2023 15:55
-
-
Save pharsi/2169842e3d16f2b37b37397afae587b5 to your computer and use it in GitHub Desktop.
List and sort directories by size on disk
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
du -sk * | sort -rg | awk '{ numBytes = $1 * 1024; numUnits = split("B K M G T P", unit); num = numBytes; iUnit = 0; while(num >= 1024 && iUnit + 1 < numUnits) { num = num / 1024; iUnit++; } $1 = sprintf( ((num == 0) ? "%6d%s " : "%6.1f%s "), num, unit[iUnit + 1]); print $0; }' | |
# Thanks to answer here at https://unix.stackexchange.com/questions/4681/how-do-you-sort-du-output-by-size |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment