How to find a file whose size is less than 10 MB?

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


Solution 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

Solution 2:

The inquirer is asking two different questions: 1) how to locate files with a particular filename whose size is less than 10 MB ("...a file whose size is...") and 2) how to locate all files whose sizes are less than 10 MB ("...the files whose size are..."). And so far the answerers above have only answered number 2.

Locate all files called filename.txt (particular filename) less than 500 kB :

find /path/subpath -type f -size -500k -name filename.txt

Locate all files whose size is less than 500 kB :

find /path/subpath -type f -size -500k -ls