Link to home
Start Free TrialLog in
Avatar of reb_elmagnifico
reb_elmagnifico

asked on

Script group permission change for files and folders in Linux

Can anyone help me write a script that has the following logic:

for every file and for every folder in a directory (recursively)
change the permissions so that the group adopts the permissions of the owner

This will need to be run on a Suse Linux Enterprise Server 8 and 9.

Thanks!

REB
Avatar of Kerem ERSOY
Kerem ERSOY

I really didnt understand it.
- If what you want to do is to change rhe permissions of of a directory (recursively) then the command you'd execute will be:
chmod -R g-r .
this will Recursively change permissions becasue of the -R switch.
to change group permissions you'd use the g (meaning group) then a minus or plus sign (meaning you'll be adding or removing respctively the right) and the right will be one of r,w,x meaning read, write and execute.
So the example above will remove the read  permission from the group recursively.

But then you say "the group will adopt .." if you mean the group members will use these permissions after that yes they will.

Is this what you want ?

ASKER CERTIFIED SOLUTION
Avatar of arrkerr1024
arrkerr1024
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of reb_elmagnifico

ASKER

I'm sorry I wasn't more clear. Hopefully this helps:

I want the permissions of the group to match that of the owner for each file and folder.

For example,

drwxr-xr-x   6 userA grp1   152 Oct  9 15:05 directoryA

would change to

drwxrwxr-x   6 userA grp1   152 Oct  9 15:05 directoryA

So the group permissions change to match the user's permisssions.

Does that help?

REB
In that case:

find /some/path -type d -perm -u+rwx -exec chmod g+rwx {} \;
find /some/path -type d -perm -u+rx -a ! -perm u+w -exec chmod g+rx {} \;
it is close but not perfect tintin what if thefile has w permission already set ? then you'll grant r and x.
So I think you should recursively reset all group permissions first.
The find commands I supplied will change directories with perms:

7xx to 77x
5xx to 55x

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
g+rx will not reset already exiting write
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sorry I haven't been involved in this discussion.  Thanks for all of the great replies!

Redimido, that looks like what I need.  I will get a chance to test it out in the next couple of days.  I'll let you know.

Thanks

REB
Hi rindi

I think I understood what the used wanted to do, and it was not set the group to a fixed permissions, but if the user have r-x, then the group have r-x, if the user has r--, then the group have r--

my script is the only one that does exactly that. Not sure why REB did not award the points already.
Sorry guys for not awarding points.  I never got around to testing it.  I agree that Redimido's script looks good and deserves the points.

Thanks

REB