Results 1 to 3 of 3
Hi all,
If I want to list and sort the current folder's content based on their sizes (big files first), I can use
Code:
du * | sort -nr
and ...
- 08-25-2008 #1Linux User
- Join Date
- May 2008
- Location
- NYC, moved from KS & MO
- Posts
- 251
sort human readable output from du
Hi all,
If I want to list and sort the current folder's content based on their sizes (big files first), I can use
and the sizes are displayed in KB's. If I want the sizes to be displayed in human-readable format, I can use option -h for the du command, but the sort command will not work correctly. For example, a 8.0K file will be listed before a 4.0M file. Is there any way to sort and the output correctly for human-readable format?Code:du * | sort -nr
- 08-25-2008 #2Linux Engineer
- Join Date
- Apr 2006
- Location
- Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
- Posts
- 1,117
Hi.
If I were doing this, I'd probably do it in perl. The perl sort allows you to specify a comparison routine.
The utility at MSORT also allows the user to write a comparison routine (as it turns out, also in perl), and one then avoids all the supporting infrastructure of an entire perl script.
I think some versions of awk have a built-in sort operator, and then the conversion of items like "17K" and "33.8M" could be done in awk.
Let us know what you finally do ... cheers, drlWelcome - get the most out of the forum by reading forum basics and guidelines: click here.
90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
We look forward to helping you with the challenge of the other 10%.
( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )
- 08-25-2008 #3Linux User
- Join Date
- May 2008
- Location
- NYC, moved from KS & MO
- Posts
- 251
Thanks drl. I got the answer from
du question: sort by size & show human-readable sizes - Ubuntu Forums
Also folks are talking about adding human readable sorting support to command sort inCode:du -k * | sort -nr | cut -f2 | xargs -d '\n' du -sh
GNU Coreutils feature request: sort by human-readable disk sizes - Justinsomnia
It would be nice if we can use sort -h to sort output from du -h *


Reply With Quote