Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This question already has an answer here:

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?

share|improve this question

marked as duplicate by Tog, Breakthrough, gronostaj, Journeyman Geek, Shekhar Aug 1 '13 at 17:11

This question was marked as an exact duplicate of an existing question.

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
share|improve this answer
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
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
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 0:12

This seems work for me:

$ sudo chmod --reference foo/ baz/*
share|improve this answer
On my system (coreutils 8.13) that copies the permissions from the foo directory to each file in bar. – Paulo Almeida Jul 30 '13 at 0:15

Not the answer you're looking for? Browse other questions tagged .