Clone permissions for all files in a folder

1

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?

user1307079

Posted 2013-07-29T22:52:41.327

Reputation: 13

Question was closed 2013-08-01T17:11:39.187

Answers

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

Dominik Hadl

Posted 2013-07-29T22:52:41.327

Reputation: 161

Could I use -R to do it to all files in the dir? – user1307079 – 2013-07-29T23:03:43.190

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 – 2013-07-29T23:06:53.530

1It 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 – 2013-07-29T23:09:32.917

Good idea by Tiago CA, maybe you should provide an asterisk after the slash, without specifying -R. – Dominik Hadl – 2013-07-29T23:40:57.487

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 – 2013-07-30T00:12:55.787

@PauloAlmeida What do you mean by "flat" the directories have more than 1 directory inside of them. – user1307079 – 2013-07-30T00:26:56.227

By 'flat' I meant with no subdirectories. If there are subdirectories the script will be more complex. – Paulo Almeida – 2013-07-30T00:32:51.887

Hmmm... Is there a simple way to do it? @PauloAlmeida – user1307079 – 2013-07-30T00:41:57.687

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 – 2013-07-30T01:07:44.963

0

This seems work for me:

$ sudo chmod --reference foo/ baz/*

stderr

Posted 2013-07-29T22:52:41.327

Reputation: 9 300

2On my system (coreutils 8.13) that copies the permissions from the foo directory to each file in bar. – Paulo Almeida – 2013-07-30T00:15:07.657