On Fri, 2 Feb 2001 at 9:53am (-0500), rpjday wrote:

> On Sat, 3 Feb 2001, Matthew Melvin wrote:
>
> > On Fri, 2 Feb 2001 at 1:54pm (-0000), Tristan Hill wrote:
> >
> > > I've got the following bash function to print the name of all directories
> > > relative to the current path and change each directories permission.  The
> > > script fail to pickup directories with a space in the name though.
> > > Corrections to the script would be much appreciated.
> > >
> > >
> > > #!/bin/bash
> > >
> > > for each in `find . -name "*"`
> > >
> > > do
> > >
> > >         if [ -d "$each" ]; then
> > >
> > >                 echo "$each"
> > >                 chmod 2770 "$each";
> > >
> > >         fi
> > >
> > > done
> > >
> >
> > For this we can simplify it alot and get find to do all the work for us...
> >
> >     find . -type d -exec chmod 2770 {} \;
> >
> > ... and because the file name is never passed throug shell we don't have to
> > worry about any spaces.
>
> you might also consider using "xargs" to avoid having to run a separate
> chmod command for every single directory you locate.
>

'cept xargs isn't going to preserve your spaces.  Well it might i guess if
we get find to help out a bit...

find . -type d -printf '"%p"\n' | xargs chmod 2770

... hmm... actually as long as you're dealing with less than a couple
thousdand directories and more than a handful to make it worth while that's
prolly the 'better' sollution.  Just less clear... :)

M.

-- 
WebCentral Pty Ltd           Australia's #1 Internet Web Hosting Company
Level 1, 96 Lytton Road.           Network Operations - Systems Engineer
PO Box 4169, East Brisbane.                       phone: +61 7 3249 2583
Queensland, Australia.                            pgp key id: 0x900E515F



_______________________________________________
Redhat-list mailing list
[EMAIL PROTECTED]
https://listman.redhat.com/mailman/listinfo/redhat-list

Reply via email to