This filters out any directory whose (cumulative) content fails to exceed 512MB and then displays sizes in gigabytes. (Since this is in consistent units, you can then append | sort -n if you really want sorted results.) In this case, I typically choose not to sort so I can better see the hierarchical structure. I've taken a slightly different approach, adding -x to ensure we stay on the same filesystem (I only ever need this operation when I'm short on disk space, so why weed out stuff I've mounted within this FS tree or moved and symlinked back?) and displaying constant units to make for easier visual parsing. Here is a POSIX-compliant solution using du and awk that should work on every system. I see three trends: piping through a second du call, using complicated shell/awk code, and using other languages. There are a lot of answers here, many of which are duplicates. Here's a version which does the sorting within the AWK script and doesn't need cut: du -h | Try it without the cut command to see what it's doing. sort the results, discard the extra columns.pull out the numeric portion of the size.index the last character of the size field.print the new fields - unit, value (to make the alpha-sort work properly it's zero-padded, fixed-length) and original line.BEGIN - create a string to index to substitute 1, 2, 3 for K, M, G for grouping by units, if there's no unit (the size is less than 1K), then there's no match and a zero is returned (perfect!).I've split it into multiple lines, but it can be recombined into a one-liner. This version uses awk to create extra columns for sort keys.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |