Use:
find . -type f -size +4096c
to find files bigger than 4096 bytes.
And :
find . -type f -size -4096c
to find files smaller than 4096 bytes.
Notice the + and - difference after the size switch.
The -size
switch explained:
-size n[cwbkMG]
File uses n units of space. The following suffixes can be used:
`b' for 512-byte blocks (this is the default if no suffix is
used)
`c' for bytes
`w' for two-byte words
`k' for Kilobytes (units of 1024 bytes)
`M' for Megabytes (units of 1048576 bytes)
`G' for Gigabytes (units of 1073741824 bytes)
The size does not count indirect blocks, but it does count
blocks in sparse files that are not actually allocated. Bear in
mind that the `%k' and `%b' format specifiers of -printf handle
sparse files differently. The `b' suffix always denotes
512-byte blocks and never 1 Kilobyte blocks, which is different
to the behaviour of -ls.
What if a file exactly 4096byte? Than which line will be executing it? – Lanti – 2017-05-01T21:33:53.657
How about bigger than 100k, less then 1M in one command? – Hrvoje T – 2017-11-13T13:59:53.263
find -size -1k will not find files smaller than 1k... (bug?), but -2k works as expected. -1024c also works correctly. – akom – 2018-11-20T15:42:40.437
11
@Jay: From man find at the beginning of the "Tests" section: "Numeric arguments can be specified as +n for greater than n, -n for less than n, n for exactly n."
– Paused until further notice. – 2010-10-29T02:14:31.1604The man page mentions it towards the top and describes that + and - can apply to all switches that take numeric ('n') arguments, including what + and - mean. (Search for TESTS in the man page to find the beginning of the section where this is described) – Slartibartfast – 2010-10-29T02:24:11.443
1@Dennis Williamson: weird, + and - work in OS X, but the man page doesn't have the TESTS section. In fact, it is missing a big chunk compared to your link, it's missing TESTs, ACTIONS, OPERATORS, among others. – ceiling cat – 2010-10-29T05:48:01.743
1
It appears the GNU version of the man page has the "Tests" section, but the BSD version does not. http://www.linuxmanpages.com/man1/find.1.php
– Jay – 2010-10-29T13:07:06.8871
The solaris man page has an "Expression" section that explains it too. http://docs.sun.com/app/docs/doc/816-0210/6m6nb7m9j?l=en&a=view
– Jay – 2010-10-29T13:11:27.2108I just found out the BSD man pages do describe the +/- thing. Its way at the end of the "Primaries" section. -- All primaries which take a numeric argument allow the number to be preceded by a plus sign ( “+” ) or a minus sign ( “-” ) . A preceding plus sign means “more than n”, a preceding minus sign means “less than n” and neither means “exactly n” – Jay – 2010-10-29T14:14:43.620
1I could not get any "less than" variant to work on Ubuntu, but a
-not
"more than" variant did. – TRiG – 2019-05-08T16:16:02.457TRIG is right the less than variant fails on Ubuntu but using
-not
works, e.g.find . -type f -size +2G -not -size +3G
finds files between 2GB and 3GB. – mattst – 2019-12-07T11:05:34.667This is a legitimate documentation bug - the only use case you would generally want for find is +n or -n ; never an exact size. OP can you raise a documentation bug? – smci – 2012-12-14T18:18:41.723
I don't know why the cat wanted all files smaller or bigger. But isn't ‛find -type f -not -size 4096c‛ easier then? – ott-- – 2013-02-28T18:10:46.563