Linux: Syncronize two directories permissions, users and groups and leave file contents untouched

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.


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