I have a system where the permissions of many files are messed up. I have another system that has the same files, if I put that hard drive in, without simply overwriting the files, is there a way where I can recursively set the permissions of each file to that of this other directory? Thanks, CP

link|improve this question

43% accept rate
1  
Cross-site duplicate: Copy permissions to identical tree on linux / unix – slhck May 23 '11 at 20:46
1  
That post is close, but it doesn't work. First the stat command does not work anymore, the %Mp, and %Lp are unknown, and command wouldn't work if there exists any files in source that are not in dest, which I do. – CptanPanic May 23 '11 at 22:02
Have you looked at the other answers (the rsync one), or getfacl? – slhck May 24 '11 at 7:24
1  
I ended up using this method, and it worked: serverfault.com/questions/58277/… which used the command from @Zoredache find /var/log -type d -printf "chmod %m %p \n" > reset_perms Thanks. – CptanPanic May 25 '11 at 12:17
@CptanPanic It would be great if you could pick an answer as accepted solution or answer your own question. – Oliver Salzburg Mar 13 at 13:00
feedback

3 Answers

getfacl / setfacl.

Assume the 'good' directory is "SRC" and the 'bad' directory is 'TARGET'. Assume that you want to copy permissions recursively.

cd SRC
getfacl -R . > /tmp/good-perms.ac

cd TARGET
setfacl --restore=/tmp/good-perms.ac

It will complain about items in SRC that are not in TARGET, and will not notice items in TARGET that are not in SRC. Also, since it transfers permissions only, files with the same name but different contents will have only the permissions updated. In theory, if two objects have the same name but are different types something weird might happen. For example, if SRC/a is a file, but TARGET/a is a directory. Also, you'll need to read the getfacl man page to see how links, symlinks, and other non-file objects are treated.

link|improve this answer
feedback

Did you try;

cp -pr

"p" flag keeps ownership, timestamp and "r" flag run command recursively.

link|improve this answer
I didn't want to copy the contents of files, just their permissions. – CptanPanic May 25 '11 at 12:18
sorry for misunderstanding. – wolfiem May 27 '11 at 8:04
feedback

I think getfacl and setfacl would be the way to go.

link|improve this answer
1  
Could you please explain how you would use these to solve the problem? – nhinkle Dec 26 '11 at 5:42
feedback

Your Answer

 
or
required, but never shown

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