This post was originally published on go2linux.org, a Linux blog I ran from 2007 to 2011. The domain is no longer mine, but I am the original author. I am republishing it here on garron.me with corrections and improvements.
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.