Monday, December 27, 2010

How to copy file permissions from one file to another


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

No comments: