problem with find's -size and -exec options
Eric Blake
eblake@redhat.com
Mon May 14 22:54:00 GMT 2012
On 05/14/2012 04:29 PM, j. k. colligan wrote:
> Friends -
>
> I just noticed a difference in behavior between Cygwin's "find" and
> the one in Linux, or
> so it seems.
>
> I was trying to locate files smaller than a given size, and thus ran
>
> find . -size -4000c
>
> That worked, and listed the file names only for files < 4000 bytes in
> size. But if I run
>
> find . -size -4000c -exec ls -l {} \;
>
> it turns out that *all* files are listed! (Plus the small ones at the
> end of the list.) This
> surprised me. In other similar cases I've run in the past, the
> earlier-in-the-command-line
> filters took effect before the exec.
Compare 'stat .' on Linux and on cygwin. On Linux, directories have
non-negligible size, typically as a multiple of 4k, and generally
accurately measured according to underlying inodes consumed by the
directory; so, for a non-empty directory, it will have size 4096, and be
filtered out by your '-size -4000c'. On Cygwin, directory size is
typically faked as 0 (since Windows doesn't really give cygwin any thing
better to work with while still remaining efficient). POSIX says that
the st_size of a stat() on a directory is undefined (the Linux
definition makes more sense, but cygwin isn't breaking POSIX by
returning 0 instead of jumping through hoops to invent a reasonable
non-zero size). Therefore, '-size -4000c' doesn't filter '.'.
The reason -exec is listing everything is that on cygwin, you ended up
passing '.' as one of the arguments to list. You can use '-type f' to
filter out directories.
> Same unexpected (to me) result. Am I way outta whack here, of is this
> a real problem?
I'll let you draw your own answer to that question :) But I don't see
any way to change findutils or cygwin to work around this difference in
directory st_size.
--
Eric Blake eblake@redhat.com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 620 bytes
Desc: OpenPGP digital signature
URL: <http://cygwin.com/pipermail/cygwin/attachments/20120514/18291864/attachment.sig>
More information about the Cygwin
mailing list