[X-Unix] question about 'find'

Eugene list-themacintoshguy at fsck.net
Mon Nov 28 02:35:42 PST 2005


On Sun, Nov 27, 2005 at 02:57:26AM CST, Xavier Noria <fxn at hashref.com> wrote:
: On Nov 27, 2005, at 4:56, Albert Lunde wrote:
: >On Sat, Nov 26, 2005 at 09:24:35PM -0600, Charles Howse wrote:
: >>
: >>$ find ~/bin -name \*.sh -maxdepth 1 -perm 0644 -exec chmod 744 {} \;
: >>
: >>This works as expected (I found the '\;' part on a web
: >>site), but  I'm not sure why I have to use the '\' as the
: >>next-to-last character.
: >>Can't find anything about it in 'man find'.
: >>Can anyone enlighten me?
: >>If I missed it in 'man find', please point me to the correct
: >>section.  :-)
: >
: >The semicolon is the delimiter for the end of the command being run
: >by "-exec", the backslash is necessary to quote it and keep it
: >from being interpreted as by the shell running "find".
: 
: In fact, unless I want -exec to behave as a boolean test that  
: modifies the list of files "founded", the way -name does, I use find 
: (1) for finding the list of files I am interested in, and execute  
: what I want afterwards in a separate command. For instance like this:
: 
:    $ find ~/bin -name '*.sh' -maxdepth 1 -perm 0644 | xargs chmod 744
: 
: I find this much more clear.

Sending the list of filenames to xargs(1) is always nice,
especially because it is much more efficient and speedier.
However, unlike other flavors, OS X filenames tend to contain
whitespace characters that break traditional Unix tools that
assume whitespace delimiters.  So to be safe, change the above
command to this:

	find ~/bin -name '*.sh' -maxdepth 1 -perm 0644 -print0 | xargs -0 chmod 744


-- 
Eugene
http://www.coxar.pwp.blueyonder.co.uk/


More information about the X-Unix mailing list