Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 15 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 :… – 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 – LawrenceC 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


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.