On 2025-06-07 Scott Baker <[email protected]> wrote:
> I'm trying to find all the files in /tmp/ that less than 1MB.
> mkdir /tmp/scott
> cd /tmp/scott
> echo "Hello world" > test.txt
> find . -size -1M -type f # doesn't work
> find . -size -2M -type f # works
> find . -size -1024k -type f # works
> From what I can tell doing -size -1[kMG] doesn't output any files? It's
> pretty easy to use a non-one number with size but it's a footgun that it
> doesn't work like the user would expect.
Quoting find(1):
The + and - prefixes signify greater than and less than, as
usual; i.e., an exact size of n units does not match. Bear in
mind that the size is rounded up to the next unit. Therefore
-size -1M is not equivalent to -size -1048576c. The former only
matches empty files, the latter matches files from 0 to 1,048,575
bytes.
cu Andreas
--
`What a good friend you are to him, Dr. Maturin. His other friends are
so grateful to you.'
`I sew his ears on from time to time, sure'