[CentOS] manipulating files and directories with spaces

Wed Nov 21 10:27:09 UTC 2007
Ralph Angenendt <ra+centos at br-online.de>

William L. Maltby wrote:
> On Wed, 2007-11-21 at 10:04 +0100, Ralph Angenendt wrote:
>> Shad L. Lords wrote:
>>> find . -type type -print0 | xargs -0 chmod value
>> 
>> Or (SUSV compliant): 
>> 
>> find . -type f -exec chmod 123 {} +
> 
> Easier to type and more natural (for me). But less efficient than the
> xargs version since each file cause a new process to be spawned. For a
> very large number of items the difference would be noticeable.

Wrong.

       -exec command {} +
              This variant of the -exec option runs the specified command on
              the selected files, but the command line is built by appending
              each selected file name at the end; the total number of  invo-
              cations  of  the  command will be much less than the number of
              matched files.  The command line is built in much the same way
              that  xargs  builds  its  command lines.  Only one instance of
              ’{}’ is allowed within the command.  The command  is  executed
              in the starting directory.

And yes, that works on mostly any Unix (as said: SUSV compliant), while
many commercial unixes have "interesting" implementations of xargs and
-print0 (or don't have that at all).

Cheers,

Ralph
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://lists.centos.org/pipermail/centos/attachments/20071121/a76a21aa/attachment-0005.sig>