Friday, March 11, 2011

Copy file permissions from one file to another

I need to copy the file permission of FirstFile.jar to SecondFile.jar.

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


chmod --reference
As an example, if you have this:

-rwxrwxrwx 1 root root 0 Dec 20 15:35 FirstFile.jar
-rwx------ 1 root root 0 Dec 20 15:35 SecondFile.jar
And you run:

chmod --reference FirstFile.jar SecondFile.jar
You should then have this:

-rwxrwxrwx 1 root root 0 Dec 20 15:35 FirstFile.jar
-rwxrwxrwx 1 root root 0 Dec 20 15:35 SecondFile.jar
Just be sure, you are the owner of the files, you that you have permission to change them.