Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I need to find a file in my current directory whose size should be less than or equal to 10 MB.

ls -lh gives me the file size of each file but not sure how to find the files whose size are less than or equal to 10 MB.

host@407d:t1_snapshot$ ls -lth

Is there any way I can do that? I am running ubuntu 12.04

share|improve this question

1 Answer 1

find . -type f -size -10485760 -ls run in your current directory or you can do

find /etc/home/user/stuff -type f -size -10485760 -ls using a path

so, my format is basically

find path of -type f (file) with -size of less than (-)10485760(10MB in B) and -ls to make it pretty for you. Per Dennis' suggestion adding -maxdepth 1 would prevent recursing into subdirs, if that is what you desire

share|improve this answer
2  
-maxdepth 1 avoids recursing into subdirectories, if that's unwanted. –  Dennis Dec 10 '13 at 23:39
    
@dennis good addition. –  PsychoData Dec 10 '13 at 23:42
4  
Also, by default -size takes 512-byte blocks as its argument. For 10 MB, use -size -10000000c or -$((10**7))c. For 10 MiB, just use -size -10M. –  Dennis Dec 10 '13 at 23:48

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.