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.)

  • I'm not sure to understand. You want to change the permission on directory/files for the group permission to be like the owner? If so, then just play around with chmod. I can show you a more explicit exemple in my answer if you want to. Jun 27, 2011 at 10:22
  • In your answer it changes all files to be 775. What if one of the files originally has the permission 123? Then it must be changed to 113 and not 775. The permission I used in the question (755) is only an example, the actual permission may be anything. I want to do this programatically.
    – AnnanFay
    Jun 27, 2011 at 10:26
  • the number after chmod is just numercial permission. If you do a ls -l and you get 452 as permission, then just to chmod 442 /you_directory/. Everything is explained (pretty well) in the wikipedia page I linked to my answer. Jun 27, 2011 at 10:32
  • this appears to be a duplicate question of serverfault.com/questions/241082/…
    – ShoeLace
    Sep 29, 2011 at 2:24

3 Answers 3


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.

  • good way to do it! I forgot this trick every time xD Jun 27, 2011 at 13:12
  • Never heard of this trick! Usefull one.
    – skinp
    Jun 28, 2011 at 13:54
  • That g=u trick just saved me hours of tedious management. There goes a +1 ;-) Jan 30, 2017 at 16:32
  • i had a bunch of files owned by my user that i wanted to share with all users. so i did chmod -R ag=u ${path_to_directory} Feb 24, 2017 at 13:10

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:


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!

  • 1
    Shouldn't it be ${p:0:1}${p:0:1}${p:2:1}?
    – minaev
    Jun 27, 2011 at 12:05
  • Yeah, your right. It weirdly worked my way as well.
    – AnnanFay
    Jun 27, 2011 at 12:13
  • Someone please explain the downvote?
    – AnnanFay
    Jun 27, 2011 at 13:02
  • Not me, but I'd like to compensate. This is a good solution that works.
    – minaev
    Jun 27, 2011 at 14:04
  • 1
    I'd say it is safer to use dangerous commands in scripts than manually. In well tested scripts, that is :). On the other hand, chmod is far from being a really, really dangerous command. Compared to rm, I mean, or rsync --delete or some others.
    – minaev
    Jun 28, 2011 at 14:08

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.

  • I've added some clarification to the question. The files may not have the same owner permissions, so if chmod is to be used there must be a way of extracting the owner permissions before passing it to chmod?
    – AnnanFay
    Jun 27, 2011 at 10:21
  • it's tricky, but the ls -l command must give you the permission, but it will be in this form -rw-rw-r--. The problem is you MUST NOT use a script to work with chmod! you must first get all the permission off the file. Then chmod to have the good right for the group. I'll edit my answer to show an exemple. Jun 27, 2011 at 10:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.