Unix: Is there a way to "copy" file or directory permissions?

Solution 1:

The GNU version of the chmod utility can copy the mode from one file (RFile) to another (file).

chmod --reference=RFile file

GNU coreutils is found in most Linux distributions and Cygwin, among other places. Not all chmod implementations provide this option.

Solution 2:

I came up with this:

find $SOURCE -mindepth 1 -printf 'chmod --reference=%p\t%p\n'|sed "s/\t$SOURCE/ $DEST/g"|sh

It is not fully bullet proof, but does what I need.

Solution 3:

try this:

find /PATH/TO/TARGET -exec chmod --reference /PATH/TO/SOURCE/{} {} \;

this would go up recursivly and chmod every file, if two directory don't match on files you will see lots of "No such file or directory" error.