How to Copy File Permissions and Ownership to Another File in Linux

Assuming you have two files or you have just created a new file and want it to have the same permissions and ownership of an older file.

In this article, we will show you how to copy permissions and ownership from one file to another file in Linux using chmod and chown commands respectively.

Copy File Permissions to Another File

To copy file permissions from one file to another file, use chmod command with the --reference switch in the following syntax, where reference_file is the file from which permissions will be copied rather than specifying mode (i.e octal or numerical mode permissions) for file.

$ chmod --reference=reference_file file

For example,

$ ls -l users.list
$ ls -l keys.list
$ sudo chmod --reference=users.list keys.list
$ ls -l keys.list
Copy File Permissions to Another File
Copy File Permissions to Another File

Copy File Ownership to Another File

Likewise, to copy ownership from another file, use chown command with the --reference switch as well using the following syntax, where reference_file is file from which owner and group will be copied rather than specifying owner:group values for file.

$ chown --reference=reference_file file

For example,

$ ls -l keys.list
$ touch api.list
$ ls -l keys.list
$ sudo chown --reference=keys.list api.list
$ ls -l api.list
Copy File Ownership to Another File
Copy File Ownership to Another File

You can also copy file permissions and ownership from one file to multiple files as shown.

$ sudo chmod --reference=users.list users1.list users2.list users3.list
$ sudo chown --reference=users.list users1.list users2.list users3.list

For more information, refer to the chown and chmod man pages.

$ man chown
$ man chmod 

You will also find these guides concerning file permissions to be useful:

  1. How to Manage Users and Groups in Linux
  2. Translate rwx Permissions into Octal Format in Linux
  3. How to Find Files With SUID and SGID Permissions in Linux

That’s all! If you know any other way to copy or clone file permissions in Linux, do share with us via the feedback form below.

Hey TecMint readers,

Exciting news! Every month, our top blog commenters will have the chance to win fantastic rewards, like free Linux eBooks such as RHCE, RHCSA, LFCS, Learn Linux, and Awk, each worth $20!

Learn more about the contest and stand a chance to win by sharing your thoughts below!

Aaron Kili
Aaron Kili is a Linux and F.O.S.S enthusiast, an upcoming Linux SysAdmin, web developer, and currently a content creator for TecMint who loves working with computers and strongly believes in sharing knowledge.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

4 Comments

Leave a Reply
  1. Thank you for your article.

    May I use the “–reference=” key for folders, not only files?

    For example, to copy permissions or owner on catalog CATALOG1 with all files located in this folder to CATALOG2?

    Reply
    • @Alexey

      You are welcome.

      And you can copy the permissions and ownership of CATALOG1 to CATALOG2. Then use the -p flag of the cp command to preserve permissions and ownership while copying files from CATALOG1 to CATALOG2 like this:

      $ chown --reference=CATALOG1 CATALOG2
      $ chmod --reference=CATALOG1 CATALOG2
      $ cp -p ./CATALOG1/* ./CATALOG2/
      

      I hope this makes sense to you.

      Reply

Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.