image
image

Go Back   macosx.com > Mac Help Forums > Unix & X11

Reply
 
Thread Tools
  #1  
Old October 8th, 2005, 11:26 AM
Registered User
 
Join Date: Aug 2001
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
giobbi is on a distinguished road
How to sort it right with du -h | sort ????

Hi all.

i wanna sort a directory after Gb/Mb/kb. When doing a du -d1 -h it show upp by Gb and Mbs. Then i wanna sort it by size, Gb then Mb. I cant make sort to sort it right, anyone knows how?

My line right now is: du -d1 -h | sort -n

But it sorts by number and not size.

Maybe i should do a: du -d1 | sort -n | ?????

But i dont know what the third pipe would be..



Thx.

p.
Reply With Quote
  #2  
Old October 9th, 2005, 09:40 AM
Cat's Avatar
Cat Cat is offline
Registered User
 
Join Date: Jan 2003
Location: @ my Mac
Posts: 1,972
Thanks: 0
Thanked 0 Times in 0 Posts
Cat is on a distinguished road
sort -n only looks at the numeric value, if you use du with the -h option the G, M and k screw up the results, i.e. 350 kB is more than 5 GB because 350 > 5. Drop the -h and use sort -nr the r flag means reverse, i.e. from biggest to smallest.

Try du -d1 | sort -nr
__________________
This is not a signature (but I could be wrong).
15" MacBook Pro C2D@2.4 GHz | 2 GB RAM | Mac OS 10.5.4 |
Website | LinkedIn | Publications
GP/O d-(+)@ s: a->? C++(+++) U* P+ L+>++ !E---- W+++ N o? K? w--- O? M++ V? PS+++ PE-- Y+ PGP t 5? X- R !tv b++++ DI+(++)@ D+(++) G++(+++) e+++$>++++$$ h--->---- r+++ y++++@
Reply With Quote
  #3  
Old October 9th, 2005, 11:15 AM
Registered User
 
Join Date: Aug 2001
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
giobbi is on a distinguished road
Thx for replying. Kinda figured that. The problem is that i have to "humanize" the output so anyone can understand the numbers...
Reply With Quote
  #4  
Old November 17th, 2005, 08:41 PM
Registered User
 
Join Date: Nov 2005
Location: North Carolina
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
phinsman is on a distinguished road
How about making it into a CSV file that can be opened via a spreadsheet, and then formatted from there? It may still not be what you're looking for, but here's an example:

du -d1 Library/ | sort -n | awk '{printf "\"%-s\",\"%d\"\n", $2, $1}' > sizes.csv

Now cat the CSV file, which has the doublequotes around the values in addition to the commas:

"Library//Address","0"
"Library//Assistants","0"
"Library//Audio","0"
"Library//Autosave","0"
"Library//Classic","0"
"Library//ColorPickers","0"
"Library//Fonts","0"
"Library//Keyboard","0"
"Library//Phones","0"
"Library//Printers","0"
"Library//Sounds","0"
"Library//iMovie","0"
"Library//iTunes","0"
"Library//Documentation","8"
"Library//Internet","16"
"Library//Icons","24"
"Library//Workflows","48"
"Library//Recent","56"
"Library//Automator","64"
"Library//FontCollections","72"
"Library//Keychains","80"
"Library//Favorites","120"
"Library//Logs","136"
"Library//Mail","136"
"Library//Cookies","152"
"Library//Syndication","832"
"Library//MarbleBlast","864"
"Library//Safari","1504"
"Library//Preferences","3040"
"Library//InputManagers","3632"
"Library//Thunderbird","7488"
"Library//Widgets","14976"
"Library//Application","18568"
"Library//Mail","18728"
"Library//Caches","205776"
"Library/","276344"

A note about this...awk/gawk has lots of abilities that I don't know about personally...it may be possible to get awk to format the number the way you want with printf or whatever.

Dale
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off
Forum Jump


All times are GMT -5. The time now is 01:10 AM.


Mac Support® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0
Copyright 2000-2008 DigitalCrowd, Inc.