Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
add comment

1 Answer

up vote 11 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
2  
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
add comment

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.