Take the 2-minute tour ×

I have two files in a directory. One has correct permissions and the other has not. Is there a way I can "copy" the set of permissions from one file to another?

share|improve this question

2 Answers 2

up vote 13 down vote accepted

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.

share|improve this answer
Hm... looks like this is supposed to work, but not supported on Mac OS X? There I only get illegal option... –  Svish Feb 28 '10 at 16:18
chmod is not a bash builtin command. it is a separate utility available on many unixes. the --reference option is included in the GNU version; OSX probably uses a chmod that originates with BSD instead. OSX man chmod : developer.apple.com/Mac/library/documentation/Darwin/Reference/… –  quack quixote Feb 28 '10 at 16:31
Svish, you might consider installing the GNU versions through MacPorts. –  Nerdling Mar 1 '10 at 23:31
Just figured that it would be useful to mention here that cp -dpR <source-file> <dest-file> will, when copying a file, copy permissions as well as the file.r –  ultrasawblade Mar 14 '11 at 13:57

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.

share|improve this answer

Your Answer


