Advance

How to copy file permissions and Ownership to another file in Linux

How to copy file permissions and Ownership to another file in Linux
1
(1)

A Linux system administrator needs to know some Linux tricks. In this article, you are going to learn how to copy file permissions and Ownership to another file in Linux. It is so normal to face a situation that you need to have the same permissions and ownership of an older file when you have two files or you have just created a new file.

Using chmod and chown commands respectively, you would learn how to do this.

 

 

How to copy file permissions and Ownership to another file in Linux

In case 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.

Recommended Article: How to configure Cowpatty on ubuntu 20.04

Copy File Permissions to Another File

When you need to copy file permissions from one file to another file, you can use chmod command with the –reference switch in the following Linux syntax, where reference_file is the file from which permissions will be copied rather than specifying mode for a file.

chmod --reference=reference_file file

You can see the below as an example.

ls -l users.list  $ ls -l keys.list  $ sudo chmod --reference=users.list keys.list  $ ls -l keys.list    view permission on linux      

Buy Linux Virtual Private Server

 

Copy File Ownership to Another File

And again when you decide to copy ownership from another file, you can use chown command with the –reference switch as well using the following syntax, where reference_file is a file from which owner and group will be copied rather than specifying owner:group values for the file.

chown --reference=reference_file file

You may also be interested in:

https://eldernode.com/disable-selinux-temporarily-permanently/

 

Now, let’s see the above command example.

ls -l keys.list  touch api.list  ls -l keys.list  sudo chown --reference=keys.list api.list  ls -l api.list

view key list on linux

Also, you can use the below command to copy permissions and ownership from one file to multiple files

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

In case you prefer to get more information, refer to the chown and chmod man pages.

man chown  man chmod

 

Dear user, we wish this tutorial would be helpful for you, to ask any question or review the conversation of our users about this article, please visit Ask page. Also to improve your knowledge, there are so many useful tutorials ready for Eldernode training.

How useful was this post?

Click on a star to rate it!

Average rating 1 / 5. Vote count: 1

No votes so far! Be the first to rate this post.

View More Posts
Tom Veitch
Eldernode Writer
We Are Waiting for your valuable comments and you can be sure that it will be answered in the shortest possible time.

Leave a Reply

Your email address will not be published. Required fields are marked *

We are by your side every step of the way

Think about developing your online business; We will protect it compassionately

We are by your side every step of the way

+8595670151

7 days a week, 24 hours a day