How to find files within a size range?

13,483

Solution 1

find -iname "*.zip" -size +$((60*1024*1024))c -size -$((70*1024*1024))c

do NOT use the abreviations 60M and 70M as this will also exclude all files of size greater than 69MB including 69.001MB!!!

from the info documentation section 2.4 Size

-- Test: -size n[bckwMG]
    True if the file uses N units of space, rounding up.
    ...

so 69.001 gets rounded up to 70 and thus gets excluded!

perfect example is find . -size -1M which will only match files of size zero.

Solution 2

find -iname "*.zip" -size +60M -size -70M

You can also use -o to get a disjunction, and \( … \) to group various matches.

Share:
13,483

Related videos on Youtube

Neel
Author by

Neel

Updated on September 18, 2022

Comments

  • Neel
    Neel over 1 year

    Please suggest me the way to find all the zip files which are more than 60 MB but less than 70 MB in size using find command.

    • DavidPostill
      DavidPostill over 8 years
      Welcome to Super User. We are not a script writing service. We expect users to tell us what they have tried so far (including any scripts they are using) and where they're stuck so that we can help with specific problems. Questions that only ask for scripts are too broad and are likely to be put on hold or closed. Please read How do I ask a good question?.
  • Kamil Maciorowski
    Kamil Maciorowski almost 6 years
    Things to consider: (1) I think your answer adds nothing new, because -a is the default operator, the other answer uses it implicitly. If your answer explained this behavior along with other parts of the find syntax, then it would be of some value. In my opinion for now it's just an unnecessarily complex (why -exec du?) general (no zip-related filter) alternative. (2) The other answer is a community wiki. It's like an invitation to improve it instead of writing a concurrent answer; so if you really have something to add, the best thing to do is to edit the community wiki answer.
  • Sridhar Sarnobat
    Sridhar Sarnobat about 5 years
    Yeah I'm experiencing this quirk now when trying to bucketize my video files. Some sizes just don't fall into any bucket.
  • halloleo
    halloleo over 4 years
    This hint is soooo good!