find and chmod

  • Follow


I'm running the following on an nfs file system housed on a NetApp:

sudo find . -type d -name .snapshot -prune -exec chmod g+s \{}

I want to set the sgid bit for all directories from here down.  It's
deep so I don't want to do it by manually but this doesn't seem to
work, whereas setting it individually does.

Thanks.

~F
0
Reply Faeandar 4/20/2004 7:14:28 PM

On Tue, 20 Apr 2004 19:14:28 GMT, Faeandar <mr_castalot@yahoo.com>
wrote:

>I'm running the following on an nfs file system housed on a NetApp:
>
>sudo find . -type d -name .snapshot -prune -exec chmod g+s \{}
>
>I want to set the sgid bit for all directories from here down.  It's
>deep so I don't want to do it by manually but this doesn't seem to
>work, whereas setting it individually does.
>
>Thanks.
>
>~F

Nevermind, found my problem.  The command should actually look like:

sudo find . -type d -name .snapshot -prune -o -type d -exec chmod g+s
{} \;

This looks to be working a little better.  The "\{}" was actually a
typo.  I really was doing "{} \;".

I think the problem was the -o option.

~F
0
Reply Faeandar 4/20/2004 8:43:22 PM


Faeandar wrote:
> Nevermind, found my problem.  The command should actually look like:
> 
> sudo find . -type d -name .snapshot -prune -o -type d -exec chmod g+s
> {} \;

Actually, given that this is comp.unix.solaris, the command should 
actually look like:

sudo find . -type d -name .snapshot -prune -o -type d -exec chmod g+s {} +

Note final character. Faster.

MB
0
Reply Mohun 4/21/2004 3:54:43 AM

On Wed, 21 Apr 2004 03:54:43 GMT, Mohun Biswas <m.biswas@invalid.addr>
wrote:

>Faeandar wrote:
>> Nevermind, found my problem.  The command should actually look like:
>> 
>> sudo find . -type d -name .snapshot -prune -o -type d -exec chmod g+s
>> {} \;
>
>Actually, given that this is comp.unix.solaris, the command should 
>actually look like:
>
>sudo find . -type d -name .snapshot -prune -o -type d -exec chmod g+s {} +
>
>Note final character. Faster.
>
>MB

Ok, now I'm curious.  What's the difference?  I was reading the man
page from a Solaris 8 box that listed the \;.

Thanks.

~F
0
Reply Faeandar 4/21/2004 6:35:26 PM

Faeandar wrote:

> On Wed, 21 Apr 2004 03:54:43 GMT, Mohun Biswas <m.biswas@invalid.addr>
> wrote:

>>Faeandar wrote:

>>>sudo find . -type d -name .snapshot -prune -o -type d -exec chmod g+s
>>>{} \;

>>sudo find . -type d -name .snapshot -prune -o -type d -exec chmod g+s {} +
>>
>>Note final character. Faster.

> Ok, now I'm curious.  What's the difference?

With the "+", it will group things together.  So, for example, if you
have three directories A, B, and C, the semicolon variation will do

	chmod g+s A
	chmod g+s B
	chmod g+s C

but the plus-sign variation will do

	chmod g+s A B C

If you have a whole lot of directories (or files), find will
still break it up into groups.

The latter is faster because it only invokes chmod one time,
which means fewer processes being created, etc., etc.

The plus-sign syntax for find is a relatively new feature of
Solaris, and the feature doesn't exist on several other versions
of Unix.

   - Logan
0
Reply Logan 4/21/2004 7:52:03 PM

Logan Shaw <lshaw-usenet@austin.rr.com> writes:

> Faeandar wrote:
>
>> On Wed, 21 Apr 2004 03:54:43 GMT, Mohun Biswas <m.biswas@invalid.addr>
>> wrote:
>
>>>Faeandar wrote:
>
>>>>sudo find . -type d -name .snapshot -prune -o -type d -exec chmod g+s
>>>>{} \;
>
>>>sudo find . -type d -name .snapshot -prune -o -type d -exec chmod g+s {} +
>>>
>>>Note final character. Faster.
>
>> Ok, now I'm curious.  What's the difference?
>
> With the "+", it will group things together.  So, for example, if you
> have three directories A, B, and C, the semicolon variation will do
>
> 	chmod g+s A
> 	chmod g+s B
> 	chmod g+s C
>
> but the plus-sign variation will do
>
> 	chmod g+s A B C

So, is 

find . -type d -name .snapshot -prune -o -type d -exec chmod g+s {} +

the same as

find . -type d -name .snapshot -prune -o -type d | xargs chmod g+s

??

Bye, Dragan
-- 
Dragan Cvetkovic, 

To be or not to be is true. G. Boole      No it isn't.  L. E. J. Brouwer

!!! Sender/From address is bogus. Use reply-to one !!!
0
Reply Dragan 4/21/2004 7:58:30 PM

Dragan Cvetkovic wrote:
> So, is 
> 
> find . -type d -name .snapshot -prune -o -type d -exec chmod g+s {} +
> 
> the same as
> 
> find . -type d -name .snapshot -prune -o -type d | xargs chmod g+s
> 
> ??

It's similar, but not the same.  The former doesn't send the filenames
through a pipe, and it is "find" that is the parent of the chmod
processes.  Also, the latter will not work properly if the filenames
have spaces in them, because xargs treats both spaces and newlines
as separators in the list of filenames.  (I never understood why
xargs doesn't have a switch to treat only newlines as separators.
Then it would at least work for the case of filenames that have
spaces but not newlines, which is a very large percentage of the
cases even though newlines are legal in filenames.)

   - Logan
0
Reply Logan 4/21/2004 8:17:22 PM

Logan Shaw <lshaw-usenet@austin.rr.com> writes:

> Dragan Cvetkovic wrote:
>> So, is find . -type d -name .snapshot -prune -o -type d -exec chmod g+s
>> {} +
>> the same as
>> find . -type d -name .snapshot -prune -o -type d | xargs chmod g+s
>> ??
>
> It's similar, but not the same.  The former doesn't send the filenames
> through a pipe, and it is "find" that is the parent of the chmod
> processes.  Also, the latter will not work properly if the filenames
> have spaces in them, because xargs treats both spaces and newlines
> as separators in the list of filenames.  (I never understood why
> xargs doesn't have a switch to treat only newlines as separators.
> Then it would at least work for the case of filenames that have
> spaces but not newlines, which is a very large percentage of the
> cases even though newlines are legal in filenames.)
>

Thanks Logan. I am sure xargs has some switch to deal with file names with
spaces (like -I) but there are too many options and too many different
flavours of it (my man page mentions /usr/bin/xargs and
/usr/xpg6/bin/xargs).

Bye, Dragan

-- 
Dragan Cvetkovic, 

To be or not to be is true. G. Boole      No it isn't.  L. E. J. Brouwer

!!! Sender/From address is bogus. Use reply-to one !!!
0
Reply Dragan 4/21/2004 8:30:19 PM

In article <lmad15hzmh.fsf@privacy.net>,
 Dragan Cvetkovic <me@privacy.net> wrote:

> So, is 
> 
> find . -type d -name .snapshot -prune -o -type d -exec chmod g+s {} +
> 
> the same as
> 
> find . -type d -name .snapshot -prune -o -type d | xargs chmod g+s
> 
> ??

Yes, unless any of the filenames contain whitespace.  Find will do the 
right thing, xargs will treat them as multiple filenames.

-- 
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
0
Reply Barry 4/21/2004 9:08:13 PM

In article <lm65bthy5g.fsf@privacy.net>,
 Dragan Cvetkovic <me@privacy.net> wrote:

> Thanks Logan. I am sure xargs has some switch to deal with file names with
> spaces (like -I) but there are too many options and too many different
> flavours of it (my man page mentions /usr/bin/xargs and
> /usr/xpg6/bin/xargs).

Standard find and xargs don't have any way to deal with them, but GNU 
find and xargs have -print0 annd -0, respectively -- they use a null 
byte to delimit filenames rather than whitespace.

-- 
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
0
Reply Barry 4/21/2004 9:09:25 PM

Logan Shaw wrote:
> The plus-sign syntax for find is a relatively new feature of
> Solaris

Actually it's quite an *old* feature of Solaris - Casper Dik said right 
here in this NG last year that it's been present since Solaris 2.0. They 
just forgot to document it for 10 years or so.

> and the feature doesn't exist on several other versions of Unix.

It's in SUSv3 so it's not a Solaris-only feature per se. Of course older 
versions of non-Solaris platforms might not have it yet.

MB
0
Reply Mohun 4/21/2004 11:38:46 PM

Mohun Biswas wrote:
> Logan Shaw wrote:
> 
>> The plus-sign syntax for find is a relatively new feature of
>> Solaris
> 
> 
> Actually it's quite an *old* feature of Solaris - Casper Dik said right 
> here in this NG last year that it's been present since Solaris 2.0. They 
> just forgot to document it for 10 years or so.

Wasn't that Casper, me, Thomas or any combination of the three?  :-)

It's documented in the Solaris 9 find(1) manpage

      -exec command
            True if the executed command returns a zero  value  as
            exit  status. The end of command must be punctuated by
            an escaped semicolon (;). A  command  argument  {}  is
            replaced  by  the current path name. If the last argu-
            ment to -exec is {} and you specify + rather than  the
            semicolon  (;),  the  command  will  be  invoked fewer
            times, with {} replaced by groups of pathnames.


> 
>> and the feature doesn't exist on several other versions of Unix.
> 

Not on MacOS 10.3.3 - just tried it.

> 
> It's in SUSv3 so it's not a Solaris-only feature per se. Of course older 
> versions of non-Solaris platforms might not have it yet.


Hmmm.  There's a thought.  I wonder if the SVR3 on my ancient AT&T 
3B2/500 supports it... Must blow the dust off the thing and switch it on!

-- 
Tony

0
Reply Tony 4/22/2004 12:02:57 PM

Tony Walton <tony.walton@s_u_n.com> writes:

> Mohun Biswas wrote:
>> Logan Shaw wrote:
>>
>>> The plus-sign syntax for find is a relatively new feature of
>>> Solaris
>> Actually it's quite an *old* feature of Solaris - Casper Dik said right
>> here in this NG last year that it's been present since Solaris 2.0. They
>> just forgot to document it for 10 years or so.
>
> Wasn't that Casper, me, Thomas or any combination of the three?  :-)
>
> It's documented in the Solaris 9 find(1) manpage
>
>       -exec command
>             True if the executed command returns a zero  value  as
>             exit  status. The end of command must be punctuated by
>             an escaped semicolon (;). A  command  argument  {}  is
>             replaced  by  the current path name. If the last argu-
>             ment to -exec is {} and you specify + rather than  the
>             semicolon  (;),  the  command  will  be  invoked fewer
>             times, with {} replaced by groups of pathnames.
>

Tony, this text needs impovements. You can't say "The end of command must
be punctuated by ;" and then say "if the end is {} + then ...".

Or you can, for a rather specific definition of "must" ...

Bye, Dragan

-- 
Dragan Cvetkovic, 

To be or not to be is true. G. Boole      No it isn't.  L. E. J. Brouwer

!!! Sender/From address is bogus. Use reply-to one !!!
0
Reply Dragan 4/22/2004 1:46:56 PM

Tony Walton <tony.walton@s_u_n.com> writes:
>> Logan Shaw wrote:
>>> The plus-sign syntax for find is a relatively new feature of
>>> Solaris

> I wonder if the SVR3 on my ancient AT&T 3B2/500 supports it...

Possibly not; see David Korn's posting about when he added it:
http://opengroup.org/austin/mailarchives/austin-group-l/msg03065.html


Markus
0
Reply mgyger 4/22/2004 2:34:53 PM

In article <4087B471.7060808@s_u_n.com>,
Tony Walton  <tony.walton@s_u_n.com> wrote:
>Mohun Biswas wrote:
>> Logan Shaw wrote:
>> 
>>> The plus-sign syntax for find is a relatively new feature of
>>> Solaris
>> 
>> 
>> Actually it's quite an *old* feature of Solaris - Casper Dik said right 
>> here in this NG last year that it's been present since Solaris 2.0. They 
>> just forgot to document it for 10 years or so.
>
>Wasn't that Casper, me, Thomas or any combination of the three?  :-)
>
>It's documented in the Solaris 9 find(1) manpage
>
>      -exec command
>            True if the executed command returns a zero  value  as
>            exit  status. The end of command must be punctuated by
>            an escaped semicolon (;). A  command  argument  {}  is
>            replaced  by  the current path name. If the last argu-
>            ment to -exec is {} and you specify + rather than  the
>            semicolon  (;),  the  command  will  be  invoked fewer
>            times, with {} replaced by groups of pathnames.
>

And it is a feature found in POSIX.1-2001, so every recent OS should 
support it!

-- 
EMail:joerg@schily.isdn.cs.tu-berlin.de (home) J�rg Schilling D-13353 Berlin
      js@cs.tu-berlin.de		(uni)  If you don't have iso-8859-1
      schilling@fokus.fraunhofer.de	(work) chars I am J"org Schilling
URL:  http://www.fokus.fraunhofer.de/usr/schilling ftp://ftp.berlios.de/pub/schily
0
Reply js 4/22/2004 10:37:40 PM

In article <c69hfk$ek4$1@news.cs.tu-berlin.de>,
Joerg Schilling <js@cs.tu-berlin.de> wrote:
>In article <4087B471.7060808@s_u_n.com>,
>Tony Walton  <tony.walton@s_u_n.com> wrote:
[...]
>>It's documented in the Solaris 9 find(1) manpage
>>
>>      -exec command
>>            True if the executed command returns a zero  value  as
>>            exit  status. The end of command must be punctuated by
>>            an escaped semicolon (;). A  command  argument  {}  is
>>            replaced  by  the current path name. If the last argu-
>>            ment to -exec is {} and you specify + rather than  the
>>            semicolon  (;),  the  command  will  be  invoked fewer
>>            times, with {} replaced by groups of pathnames.
>>
>
>And it is a feature found in POSIX.1-2001, so every recent OS should 
>support it!

Of course, it's a pretty grubby spec, breaking commands that could
have quite reasonably wanted a single + as an genuine argument. It
would have been better to have had a -execxargs (say) replacing the 
-exec verb.

Grubby, but admittedly useful.

Chris Thompson
Email: cet1 [at] cam.ac.uk
0
Reply cet1 4/24/2004 11:09:47 PM

In article <c6es3r$pi0$1@pegasus.csx.cam.ac.uk>,
 cet1@cus.cam.ac.uk (Chris Thompson) wrote:

> In article <c69hfk$ek4$1@news.cs.tu-berlin.de>,
> Joerg Schilling <js@cs.tu-berlin.de> wrote:
> >In article <4087B471.7060808@s_u_n.com>,
> >Tony Walton  <tony.walton@s_u_n.com> wrote:
> [...]
> >>It's documented in the Solaris 9 find(1) manpage
> >>
> >>      -exec command
> >>            True if the executed command returns a zero  value  as
> >>            exit  status. The end of command must be punctuated by
> >>            an escaped semicolon (;). A  command  argument  {}  is
> >>            replaced  by  the current path name. If the last argu-
> >>            ment to -exec is {} and you specify + rather than  the
> >>            semicolon  (;),  the  command  will  be  invoked fewer
> >>            times, with {} replaced by groups of pathnames.
> >>
> >
> >And it is a feature found in POSIX.1-2001, so every recent OS should 
> >support it!
> 
> Of course, it's a pretty grubby spec, breaking commands that could
> have quite reasonably wanted a single + as an genuine argument. It
> would have been better to have had a -execxargs (say) replacing the 
> -exec verb.
> 
> Grubby, but admittedly useful.

POSIX didn't invent it, they just documented the feature that has been 
around for years, and apparently hasn't caused havoc to ensue.

Just how many commands are there that take a filename argument followed 
by a lone "+"?  Yes, it's a theoretical possibility, but in practice 
it's not a serious problem.

-- 
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
0
Reply Barry 4/25/2004 2:07:40 AM

16 Replies
273 Views

(page loaded in 0.738 seconds)

Similiar Articles:


















7/24/2012 7:20:03 PM


Reply: