brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: two find -size tests give you a size range

Find
~/tips/tip-find-size-range

find /srv/downloads -type f -size +100M -size -1G -exec ls -lh {} +

Lists files between two sizes, for example everything between 100 MB and 1 GB.

Looking for big files is easy with one -size test. Sometimes you want a band in the middle, like downloads that are too big to be documents but too small to be the full film.

find /srv/downloads -type f -size +100M -size -1G -exec ls -lh {} +

find joins tests with “and” unless you say otherwise, so two size tests mean both must be true: larger than 100 MB and smaller than 1 GB. With files of 500 bytes and 2 MB, -size +100k -size -10M lists only the 2 MB one.

The units are k, M and G, which find counts in powers of 1024, so 1G is 1024M here. Mixing units is fine.

Rounding plays a role at the edges. find rounds each file up to whole units of the suffix before it compares, so -size -1G really means “0 GB after rounding up”, which only empty files pass. That’s a different answer from what most people expect, and here it would make the whole range empty. I’d use a smaller unit for the upper limit to avoid that, like -size -1024M:

find /srv/downloads -type f -size +100M -size -1024M

Further reading: find(1) manual page, GNU findutils manual

More Find tips find / -maxdepth 1 -fstype proc find /backup -name '*.gz' ! -exec gzip -t {} \; -print 2>/dev/null find /srv/data -depth -print find /srv -xdev -samefile /srv/downloads/movie.mkv find / -xdev -user olduser -ls 2>/dev/null All Find tips (46) All topics

Link