Replicate file permissions

Written by
Date: 2010-12-20 10:36:30 00:00

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.