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?

  • Downvoter, care to explain?
    – BenMorel
    Dec 17, 2013 at 11:50

2 Answers 2


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

  • Interesting. Never seen that before. But if you can read octal permissions...
    – ewwhite
    Dec 17, 2013 at 11:56
  • 1
    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, 2013 at 16:55
  • @ChrisS: The question is tagged linux ;)
    – user9517
    Dec 17, 2013 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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .