It is currently Thu, 20 Jan 2022 10:47:55 GMT



 
Author Message
 Problem using recursive chmod with find and xargs
On my Linux box I need to chmod all directories and files under a certain
location so I use these strings:

find . -type d |sed s/^/\'/|sed s/\$/\'/|xargs chmod 2775 > /dev/null 2>&1
find . -type f |sed s/^/\'/|sed s/\$/\'/|xargs chmod 664 > /dev/null 2>&1

but the problem is that I have a subdirectory underneath that is replicated
from a Windows box, so this string cannot deal with directory and file
names that contain spaces. How can I fix that? I've tried a bunch of
quoting methods but cannot seem to find the right solution.

Thanks,
Jon



 Sat, 09 Sep 2006 02:48:25 GMT   
 Problem using recursive chmod with find and xargs

I found what seems to be the right answer from a previous post by Stefan.
Sorry, I haven't visited this group before so I should have checked first.

Jon

-=-=-=-=-=-=-=-=-

With GNU find you may use:

find . -type d -print0 | xargs -0??chmod?770
find . -type f -print0 | xargs -0??chmod?660

Stefan



 Sat, 09 Sep 2006 03:26:24 GMT   
 Problem using recursive chmod with find and xargs
Dnia 2004-03-22, Jon LeBlanc napisal:

But you wouldn't get better answer:
find . -type d -exec chmod 2775 {} \;
find . -type f -exec chmod 664 {} \;
compared to

--
Stanislaw Klekot



 Wed, 13 Sep 2006 03:03:32 GMT   
 Problem using recursive chmod with find and xargs
"Stachu 'Dozzie' K." <cut-to-last-hypen-doz...@dynamit.im.pwr.wroc.pl> wrote in message <news:c41uq4$hpt$3@panorama.wcss.wroc.pl>...

Don't need to invoke 'find' more than once:

find . -type d -exec chmod 770 {} \; -o \
       -type f -exec chmod 660 {} \;



 Wed, 13 Sep 2006 19:10:42 GMT   
 Problem using recursive chmod with find and xargs
Dnia 2004-03-27, rakesh sharma napisal:
Yes, but I found that two finds are a bit faster than one with 'or'
command if you use it in directory with many files and subdirs.

--
Stanislaw Klekot



 Fri, 15 Sep 2006 20:12:31 GMT   
 Problem using recursive chmod with find and xargs
On 29 Mar 2004 12:12:31 GMT,
    Stachu 'Dozzie' K. <cut-to-last-hypen-doz...@dynamit.im.pwr.wroc.pl> wrote:

The -exec argument will invoke chmod once for each file.  Using xargs
will invoke chmod with as many filenames as possible reducing the overhead
of starting a new process for each filename.

Villy



 Fri, 15 Sep 2006 21:36:40 GMT   
 Problem using recursive chmod with find and xargs
Dnia 2004-03-29, Villy Kruse napisal:
But xargs splits filenames with spaces into few arguments passed to
chmod. So both methods have + and -.

--
Stanislaw Klekot



 Sat, 16 Sep 2006 19:12:16 GMT   
 Problem using recursive chmod with find and xargs
On 30 Mar 2004 11:12:16 GMT,
    Stachu 'Dozzie' K. <cut-to-last-hypen-doz...@dynamit.im.pwr.wroc.pl> wrote:

Of course,  that is one good reason print0 for find and -0 for xargs was
invented.  I don't know if versions other than GNU versions implement that.
I wouldn't be surprised if that wasn't the case.

Villy



 Sat, 16 Sep 2006 19:58:50 GMT   
 Problem using recursive chmod with find and xargs
"Villy Kruse" <v...@station02.ohout.pharmapartners.nl> wrote, on Tue, 30 Mar 2004:

Yes, it probably is only GNU that supports it.  (Maybe one of the
modern BSD's does?  The only BSD I've ever used was 4.2BSD.)

Many of the commercial UNIX systems implement a better solution: using
a '+' instead of ';' to terminate the -exec, as in

    find . -exec some_command '{}' +

makes find do argument aggregation itself, removing the need for
(simple uses of) xargs.  This is better than -print0/xargs -0 for at
least two reasons: it is more efficient (no need to write all the
pathnames to a pipe and read them back); and it is easier to obtain
error status (with find | xargs how do you tell if the find terminated
abnormally? - other than by visually inspecting messages on stderr, or
using the bash-specific PIPESTATUS array).

This "-exec ... +" feature is required by the latest POSIX standard,
so it should become more widespread in the future.

--
Geoff Clare <nos...@gclare.org.uk>



 Mon, 18 Sep 2006 21:09:50 GMT   
 
   [ 9 post ] 

Similar Threads

1. find xargs chmod

2. Using find with xargs

3. How to use xargs for recursive grep?

4. recursive chmod/chown

5. recursive chmod on dir

6. Recursive Chmod

7. find, xargs, grep ???

8. piping commands together/xargs/find??

9. find | head | xargs

10. Efficiently executing multiple commands with find and/or xargs


 
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software