On Tuesday 22 October 2002 09:58 pm, -JhAzEr- wrote:
> Is it possible to retain a directory (and all its subdirectories)
> permission using chmod? 

well, it's kind of hard to answer that question since it's not
really clear what you mean.

> I have directory A, under it is Directory B and C.
> I just want to change directory A and B's permission.
> Directory C remains untouched.

fortunately the examples clarifies a little.  but it's still not too
clear.  combining this and the previous quoted part, is it
more like:

you are sitting in the A directory.  Directories B and C
are under A.  perhaps Directory D is under B and Directory
E is under C.  you want to set all the permissions of A
and B to something (with Directory D under B being
damay), but you don't want C (and it's subdirectory
E) to be changed that way.

A  - change
    B  -change
        D -change
    C -don't change
        D -don't change

do you also want the files under B to be changed to the
same permissions?

a simple option would be to tar the C, chmod the whole
tree, then rm -rf C and untar the C back in place.

another way would be to 
 
   find . A > ~/filelist.txt

then, edit filelist.txt and remove all the entries 
that are in the directory you don't want to chmod.
then feed the filelist.txt to chmod as a list of files
whose modes are to be changed.

chmod [someModesHere] `~/filelist.txt`

[warning, might choke if there too many files in
the filelist {i.e., very big subtree}].

you could also write a shell script that traverses
the directory tree and chmods entire subtrees if
they are not in a list of subtrees that you want to
preserver the permissions.  it could be tricky
getting this to work right though.  i'd avoid this and
go with the first or the second if possible (might not
be possible, for instance, if one subtree whose
permissions are to be changed is /var/mail, then
the tar thing won't work right [you might lose mail]) 
unless you disable mail delivery temporarily while 
you're working.  

> is it possible? ...with only a single (chmod) command ;)

probably.  but i don't know enough grep to tell you how
if there is more than one subtree to avoid.  if there's
only one you could do:

chmod <someModesHere> `find . | grep -v \/dirToIgnore`

or something similar.  of course this is not foolproof.
if you have dirToIgnore in two different subtrees (i.e.,
you have dir1/dirToIgnore and dir2/dirToignore, and
you actually want to change the mods of dir2/dirToIgnore,
but not the one under dir1, then you're on your own,
that one liner won't help you.  you'd have to change
the mods of dir2/dirToIgnore separately, and it's
no longer a oneliner if you do that :).

the above is not meant to be exhaustive :).  those are
the first things that i thought of.  no doubt there are 
other, more clever ways.  i just haven't tried to be
clever enough to find them :).  i'd do #1 if there's no
data that could change in between.  i'd do #2 if
there is data that could change.  i'd do #3 if it's a
simple tree and there's only one directory to avoid
changing.

tiger

-- 
Gerald Timothy Quimpo  tiger*quimpo*org gquimpo*sni-inc.com tiger*sni*ph

                   Veritas liberabit vos.
_
Philippine Linux Users Group. Web site and archives at http://plug.linux.org.ph
To leave: send "unsubscribe" in the body to [EMAIL PROTECTED]

Fully Searchable Archives With Friendly Web Interface at http://marc.free.net.ph

To subscribe to the Linux Newbies' List: send "subscribe" in the body to 
[EMAIL PROTECTED]

Reply via email to