I want to find the file whose size is less than 1M, so I write as find . -size -1M
. But it seems not work indeed:
find . -size -1M | xargs ls -lh
-rw-rw-r-- 1 xyz xyz 0 Apr 2 14:48 ./test/score
-rw-rw-r-- 1 xyz xyz 0 Apr 2 14:48 ./test/ir1
On the contrary, it's amazing that find . -size 1M
works.
CodePudding user response:
From man find
:
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.