7

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

2 Answers 2

10

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

3
  • 3
    -maxdepth 1 avoids recursing into subdirectories, if that's unwanted.
    – Dennis
    Dec 10, 2013 at 23:39
  • @dennis good addition.
    – PsychoData
    Dec 10, 2013 at 23:42
  • 5
    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, 2013 at 23:48
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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