Go2Linux | Linux Operating System

A site dedicated to: Linux Operating System

How to copy file permissions from one file to another

Date: 2010-12-20 00:00:00 -0400

Introduction

You may know how to change file permissions using chmod but, if you already have a file with the permissions you want to assign to some other files, you can use --reference option in chmod

How to copy or replicate file permissions, using another file as reference

If you want to use a file as reference to copy its permissions to other files you can do that using this command

chmod --reference <reference-file> <target-file>

As an example, if you have this:

-rwxrwxrwx 1 ggarron ggarron 0 Dec 20 15:35 1.txt
-rwx------ 1 ggarron ggarron 0 Dec 20 15:35 2.txt

And you run:

chmod --reference 1.txt 2.txt

You should then have this:

-rwxrwxrwx 1 ggarron ggarron 0 Dec 20 15:35 1.txt
-rwxrwxrwx 1 ggarron ggarron 0 Dec 20 15:35 2.txt

Just be sure, you are the owner of the files, you that you have permission to change them.

If you liked this article please share it.

powered by TinyLetter

If you want to contact me in any other way, please use the contact page.