Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linux change group permission to match owner permissions

Suppose I have a directory on Linux with a bunch of files and subdirectories. This is that root directory:

drwxr-xr-x  13 user1 group1    4096 May  7 15:58 apps

Now, I only want to alter the group portion of those permissions. I want to alter it in such a way that it exactly matches the owner portion. The result for that directory would be:

drwxrwxr-x  13 user1 group1    4096 May  7 15:58 apps

But, I want a script or command to do this automatically, not just for that directory but for every subdirectory and file recursively under it. Anyone know how?

Thanks.

like image 634
Dave L. Avatar asked Sep 16 '10 14:09

Dave L.


People also ask

How do I change group ownership permissions in Linux?

To change file and directory permissions, use the command chmod (change mode). The owner of a file can change the permissions for user ( u ), group ( g ), or others ( o ) by adding ( + ) or subtracting ( - ) the read, write, and execute permissions.

Can we combine the group and ownership command?

Stupid simple command to change ownership (chown) and change group (chgrp) at the same time. To simultaneously change both the owner and group of files or directories in linux use the following command structure: chown someusername:somegroupname filename.

How do I change the group membership in Linux?

The chown command changes the owner of a file, and the chgrp command changes the group. On Linux, only root can use chown for changing ownership of a file, but any user can change the group to another group he belongs to. The plus sign means “add a permission,” and the x indicates which permission to add.

What is the meaning of chmod 777?

777 - all can read/write/execute (full access). 755 - owner can read/write/execute, group/others can read/execute. 644 - owner can read/write, group/others can read only.


1 Answers

Give this a try (test it first):

chmod -R g=u apps

The = copies the permissions when you specify a field (u, g or o) on the right side or sets it absolutely when you specify a permission (r, w or x) on the right.

like image 137
Dennis Williamson Avatar answered Oct 13 '22 00:10

Dennis Williamson