find /etc -size -1G return only empty files

Rick Stevens ricks at nerd.com
Thu Mar 25 18:44:35 UTC 2010


On 03/25/2010 11:22 AM, Chris Adams wrote:
> Once upon a time, Rick Stevens<ricks at nerd.com>  said:
>> On 03/25/2010 10:44 AM, Patrick O'Callaghan wrote:
>>> On Thu, 2010-03-25 at 10:21 -0700, Rick Stevens wrote:
>>>>           # find /etc -size 1G -exec ls -lh \{\} \;
>>>>
>>>> run as root finds files<1G as confirmed by the "ls" bit of the
>>>> command.
>>>
>>> The OP's test (and mine) was with "-size -1G". Your test uses "-size 1G"
>>> but (incorrectly) gives the result expected for "-size -1G".
>>>
>>> This really should be reported. It would be appropriate for the OP to do
>>> so as he found it.
>>
>> You are correct.  Doing "-size -1G" on both F11 and F12 return only
>> zero-length files.  Yep, that's a bug in my book.
>
> Looking at the source, it is happening because of the way the size
> suffix is implemented.  With no suffix, find works in increments of a
> blocksize of 512 (the file size in bytes is rounded up to the next
> integer multiple of the blocksize); "find -size 1" would find all files
> with a size from 1 to 512 bytes, inclusive, and "find -size -1" would
> find files with a size less than 1 (e.g. 0).
>
> GNU find implements the suffixes by changing the blocksize.  So, 1G is
> interpreted as size from 1 to 1024*1024*1024 bytes.  -1G means smaller
> than that, so still only size 0 matches.
>
> While this gives less-than-intuitive results, this is the documented
> behavior (although the documentation could be clearer).

I have to disagree that's the documented behavior either in the info or
man pages, and while find's own "--help" output is poorly laid out, it
also makes no mention of block sizes.

The man page has the most data and in it the only reference to blocks
is if you specify "b" as the scalar or in reference to the "-print",
"-ls" or "-fls" actions.
----------------------------------------------------------------------
- Rick Stevens, Systems Engineer, C2 Hosting          ricks at nerd.com -
- AIM/Skype: therps2        ICQ: 22643734            Yahoo: origrps2 -
-                                                                    -
- "I never drink water because of the disgusting things that fish do -
- in it." -- W.C. Fields                                             -
----------------------------------------------------------------------


More information about the users mailing list