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.
Related videos on Youtube
Author by
Neel
Updated on September 18, 2022Comments
-
Neel over 1 year
Please suggest me the way to find all the
zip
files which are more than60 MB
but less than70 MB
in size usingfind
command.-
DavidPostill over 8 yearsWelcome 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 almost 6 yearsThings 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 thefind
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 about 5 yearsYeah I'm experiencing this quirk now when trying to bucketize my video files. Some sizes just don't fall into any bucket.
-
halloleo over 4 yearsThis hint is soooo good!