#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2000
    Posts
    204
    Rep Power
    15

    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!
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Oct 2000
    Location
    Back in the real world.
    Posts
    5,966
    Rep Power
    191
    Code:
    find . -printf '%s %p\n'|sort -nr|head
    will give you the "top-ten"
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2000
    Posts
    204
    Rep Power
    15
    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?
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Oct 2000
    Location
    Back in the real world.
    Posts
    5,966
    Rep Power
    191
    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?
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2000
    Posts
    204
    Rep Power
    15
    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...

IMN logo majestic logo threadwatch logo seochat tools logo