1834328 Members
2730 Online
110066 Solutions
New Discussion

permission question

 
SOLVED
Go to solution
Scott J. Showalter
Frequent Advisor

permission question

My previous question (find -perm) was just an example of one permission that I was trying to use find for. My REAL issue is:

I just created a new group. I changed all of the files/directories in a specific tree to the new group. Now I want to find all of the files/directories that are in that specific tree, and change the group permissions to be the same as the owner permissions.

There might be an easier way to do that than using the find command, but I couldn't come up with one.

So I want the file/directory that has
r--XXXXXX to get changed to r--r--XXX where X is "don't care". I want the file/directory that has
rw-XXXXXX to get changed to rw-rw-XXX and
I want the file that has
rwxXXXXXX to get rwxrwxXXX

I suppose that should even include the UID and/or GID bits also. So if the original has
rwxr-sXXX
it should get changed to
rwxrwsXXX

That last condition may add way to much complexity, so I may have to address those issues individually.
In a world without fences, who needs Gates?
4 REPLIES 4
OldSchool
Honored Contributor
Solution

Re: permission question

Hmmm... how about

chmod -R g=u

haven't check down a tree, but that will set group perms = to "user" (owner).
Scott J. Showalter
Frequent Advisor

Re: permission question

I didn't know you could do that. I didn't even see that documented any where. Did I miss that in the man page?

That does exactly what I asked for. Thanks...
In a world without fences, who needs Gates?
spex
Honored Contributor

Re: permission question

Scott,

Here's how to get the numeric permissions of a file with perl:

perl -e 'printf("%04o\n",(stat($ARGV[0]))[2]&07777);' file

Use this along with some bit manipulation in a larger perl script to accomplish what you're looking for. Seems like it would be a fun little script to write, but I don't have time at the moment.

PCS
OldSchool
Honored Contributor

Re: permission question

It's kind of buried in the man page, under "Symbolic Mode List":


Or one only of the following letters:

u Copy the current user permissions to who.
g Copy the current group permissions to who.
o Copy the current other permissions to who.