Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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
-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
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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .