2

I have a question. So I have 2 folders, both of which have the same files in them, but some with different content, but the same names. What I want to do is clone all of the file permissions from one folder, into the permissions for another folder. Is this possible?

2 Answers2

0

This is a duplicate of Unix: Is there a way to "copy" file or directory permissions? .

You can achieve this by typing this:

chmod --reference=RFile file
  • Could I use -R to do it to all files in the dir? – user1307079 Jul 29 '13 at 23:03
  • I am on my phone, can't try right now, but you should probably be able to. Otherwise, you could make a script that would recurse into subdirectories and do this for all the files. – Dominik Hadl Jul 29 '13 at 23:06
  • 2
    It didnt seem to do it to recursively... I ran chmod -R --reference=/home/tcagame_svc4/karl/4/garrysmod/ /home/tcagame_svc7/stefen/7/garrysmod/ – user1307079 Jul 29 '13 at 23:09
  • Good idea by Tiago CA, maybe you should provide an asterisk after the slash, without specifying -R. – Dominik Hadl Jul 29 '13 at 23:40
  • 1
    Tiago CA's answer doesn't work for me, but this does: for i in foo/*; do j=$(basename $i); chmod bar/$j --reference foo/$j; done (you want to copy the permissions from foo to bar and they are flat directories). – Paulo Almeida Jul 30 '13 at 00:12
  • @PauloAlmeida What do you mean by "flat" the directories have more than 1 directory inside of them. – user1307079 Jul 30 '13 at 00:26
  • By 'flat' I meant with no subdirectories. If there are subdirectories the script will be more complex. – Paulo Almeida Jul 30 '13 at 00:32
  • Hmmm... Is there a simple way to do it? @PauloAlmeida – user1307079 Jul 30 '13 at 00:41
  • If you want to copy the permissions in bar to foo, go into bar and type this: find . -exec chmod --reference={} ../foo/{} \; (this assumes foo and bar are at the same level; if not, adjust the path in the exec command). – Paulo Almeida Jul 30 '13 at 01:07
-1

This seems work for me:

$ sudo chmod --reference foo/ baz/*
stderr
  • 10,394
  • 2
  • 32
  • 49