Find the answer to your Linux question:
Results 1 to 2 of 2
Hey guys, I have a folder with with sub-folders in it with quite a big number of files. I need to find a median file size in the parent folder. ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Sep 2012
    Posts
    2

    find the median filesize in a folder


    Hey guys,

    I have a folder with with sub-folders in it with quite a big number of files. I need to find a median file size in the parent folder.

    I am able to find the average size, but bit lost about finding the median file size.

    Can someone please help?

  2. #2
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    Quote Originally Posted by jd1885 View Post
    I have a folder with with sub-folders in it with quite a big number of files. I need to find a median file size in the parent folder.
    I guess you mean you want the median file size of all the files IN the parent folder? what about these sub-folders?

    I am able to find the average size, but bit lost about finding the median file size.
    How to Calculate the Median Value

    you could do this in Bash...

    1) get all the file sizes and save them to an array.

    2) sort the array.

    3) count the number of elements in the array and:
    if odd, then the middle element (file size) is your median
    if even, then the average of the two middle elements (file sizes) is your median

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •