Copy a file's owner permissions to group permissions
How can I copy a file's user/owner permissions to it's group permissions?
For example if the permissions are 755 I want them to become 775.
Clarification: 755 -> 775 123 -> 113 abc -> aac
Bonus if I can do this recursively for all files in a directory.
(That is, for every file the ownder permissions are copied to the group permissions. Each file may have different permissions.)
you can use g=u
to make the group perms the same as the user perms
ls -l file
-rw------- 1 user users 0 Jun 27 13:47 file
chmod g=u file
ls -l file
-rw-rw---- 1 user users 0 Jun 27 13:47 file
and recursively
chmod -R g=u *
or for some filespec
find /patch/to/change/perms -name '*.txt' -exec chmod g=u {} +
the chmod manpage is your friend.
As people have said, changing file permissions can be dangerous. With great power comes great responsibility, and all that shizas. This is my answer:
file /usr/bin/otog:
#!/bin/sh
f=$1
p=`stat -c "%a" $f`
chmod ${p:0:1}${p:0:1}${p:2:1} $f
Example usage:
find . -exec otog {} \;
Uses stat to get numerical permissions, uses chmod to change permissions.
PS: Please see Iain's answer for a better way of doing this!
First of all, you need to list your right.
ls -l /your_directory/
-rwxr-xr-x 1 57 Jul 3 10:13 file1
-rwxr-xr-x 1 57 Jul 3 10:13 file2
to translate the result in numerical permission use this : R = 4, W = 2, X = 1.
So on this 2 file the permission are 755.
After getting your right, you must use the chmod command to change the right the way you want :
chmod 775 /your_directory/
This command will only change the right on the directory, but not on the file inside.
If you want to change the right inside too, then do this command :
chmod 775 /your_directory/ -fR
The -fR will force the recursivity. (use it only if you are sure of the right you want to apply, and the file inside the directory.)
If you only want to change the right on file1 then :
chmod 775 /your_directory/file1
And that the way the cookies crumble!
/!\ Be carefull, misuse of this command can destroy all your OS permissions and lead to malfunction of it. /!\
ps : look there to find out more information about chmod.
Hope this will help you.