Tell me more ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

In my Linux box I have two directories:

  • work files with wrong permissions
  • older versions of the same files with the right permissions (permissions and users and groups)

I need to syncronize the permissions only without changing the file contents. I tried rsync but I can't find a suitable option. Can you give me some advice?

Thanks in advance.

EDIT

Thanks to your suggestions I have this script. It recursively changes the subtree permissions:

#!/bin/bash
cd good
find $1/* | while read DIR
do
 chown --reference="$DIR" "/bad/$DIR"
 chmod --reference="$DIR" "/bad/$DIR"
done

Not a masterpiece but it works for me.

share|improve this question
2  
use a for loop over the files and then execute for each file chmod --reference=ReferenceFile and chown --reference=ReferenceFile – mailq Nov 7 '11 at 16:52
Unless there's something else to it, Maliq's suggestion should work. Just holler if you need help with the script. – Jeffery Smith Nov 7 '11 at 17:31

1 Answer

up vote 3 down vote accepted

You can use the --reference=file switch to both chmod and chown to do this e.g.

#!/bin/bash
for FILE  in /path/to/good/directory/*
do
    chown --reference="$FILE" /path/to/bad/directory/"$(basename "$FILE")"
    chmod --reference="$FILE" /path/to/bad/directory/"$(basename "$FILE")"
done
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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