Linux Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsLinux Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old April 30th, 2002, 02:48 AM
dwh dwh is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2000
Posts: 178 dwh User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 48 sec
Reputation Power: 8
Command to find largest file within multiple subdirectories

Hi!

I have a directory called uploadfiles, and underneath that is:

user1
user2
user3

up to like user500

I'm trying to find the largest files in these /home/dwh/uploadfiles/user* directories.
Is there a way to get let's say the top 10 biggest files?

Thanks!

Reply With Quote
  #2  
Old April 30th, 2002, 12:59 PM
M.Hirsch M.Hirsch is offline
Contributing User
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Oct 2000
Location: Back in the real world.
Posts: 5,969 M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 22 h 39 m 55 sec
Reputation Power: 184
Code:
find . -printf '%s %p\n'|sort -nr|head

will give you the "top-ten"
__________________
--
Manuel Hirsch - Linux, FreeBSD, programming, administration articles, tutorials and more.

Reply With Quote
  #3  
Old April 30th, 2002, 01:56 PM
dwh dwh is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2000
Posts: 178 dwh User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 48 sec
Reputation Power: 8
Quote:
Originally posted by M.Hirsch
Code:
find . -printf '%s %p\n'|sort -nr|head

will give you the "top-ten"


Thank you so much!

If you don't mind I will repeat the code below with notes on what I understand and what I don't just so I can learn the meaning behind the code too!

"find"
searches for...

"."

within the current directory...

"-printf"

hmmm. -print would be to the screen? -printf to a file??

" '%s %p\n'"

uh...u got me there...

"|"

pipe to...

"sort"

never used sort but I guess it sorts!

"-nr"

uh...hmm no idea...

"|head"

pipe to head, like heading a file similar to tailing a file?

Reply With Quote
  #4  
Old April 30th, 2002, 02:03 PM
M.Hirsch M.Hirsch is offline
Contributing User
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Oct 2000
Location: Back in the real world.
Posts: 5,969 M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 22 h 39 m 55 sec
Reputation Power: 184
if you donīt mind...


"find"
searches for...
"."
within the current directory...

//-- no. "." is the current directory. find searches for any file in the current directory (and sub-dirs)

"-printf"

hmmm. -print would be to the screen? -printf to a file??

//-- printf is a common programming language function "print formatted"

" '%s %p\n'"
uh...u got me there...

//-- this is the format strings. from the manual ("man find") you know that
//-- %s is filesize in bytes, %p is filename with path, \n is a "new line"

"|"
pipe to...
"sort"
never used sort but I guess it sorts!
"-nr"
uh...hmm no idea...

//-- from the manual ("man sort"): numeric sort, reverse sort

"|head"

pipe to head, like heading a file similar to tailing a file?

//-- 100% correct. default is 10 lines. again, see "man head"
//-- linux is , eh?

Reply With Quote
  #5  
Old April 30th, 2002, 02:13 PM
dwh dwh is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2000
Posts: 178 dwh User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 48 sec
Reputation Power: 8
Very !!

It didn't even dawn on me to man the find command doh! Sorry

Of course I can't really understand the man explanations half the time! I usually need to see a full example in use and the result of the command...

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsLinux Help > Command to find largest file within multiple subdirectories


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway