Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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

Say I have two files:

-rw-rw-r--  1 webapp webapp   215 Jun 21  2012 index.php
-rw-rw-rw-  1 root   root      58 Dec 17 11:02 patch.log

I would like to give patch.log the same permissions as index.php.

I can do it manually:

chown webapp:webapp patch.log
chmod 664 patch.log

But this should be part of a script, where I don't necessarily know what the exact permissions of index.php are.

Is there a way to copy permissions of a given file to another file?

share|improve this question
Downvoter, care to explain? – Benjamin Dec 17 '13 at 11:50
up vote 11 down vote accepted

You can use a file as a reference file for both chown and chmod

chown --reference=index.php patch.log
chmod --reference=index.php patch.log

It's all in the man pages btw


--reference=RFILE use RFILE’s owner and group rather than specifying OWNER:GROUP values


--reference=RFILE use RFILE’s mode instead of MODE values

share|improve this answer
Interesting. Never seen that before. But if you can read octal permissions... – ewwhite Dec 17 '13 at 11:56
It's be really nice if GNU manpages specified when they added arguments/functionality outside of the POSIX standard. This works in GNU chown and chmod, but not in any other OSes. – Chris S Dec 17 '13 at 16:55
@ChrisS: The question is tagged linux ;) – Iain Dec 17 '13 at 16:57

If there's any possibility of extended ACLs on the files in question, it's better to use getfacl/setfacl:

getfacl index.php | setfacl --set-file=- patch.log
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.