Advanced 'find' against specific groups and perms
I need to search all files in directory X that do not belong to $GROUP and then -exec chgrp {} \; and then I need to find all files in directory X that do not have group rw (If they are a file) or rwx (if it's a directory) and do -exec chmod g+rw (or g+rwx) {} \;
I'm having trouble understanding how I can get find to lcoate these files that aren't belonging to $GROUP. -nogroup won't work since that just checks against non existant groups in the /etc/group file. Help me obie-wan-ka-newbie... You're meh only hope! |
Hi,
find . -type f ! -group users searches for files that do not have users as group. The ! (or -not) is used to exclude something. You can also group things like this: find . -type f -not \( -group users -o -group visitor \) All file having users or visitor as group will be excluded from the hits. Hope this clears things up a bit. |
Yea, I figured that out...
Here's what I got but it's not working as I expected...WTF?! Code:
# Project Ownership & Group permissions. |
Hi,
What's it doing, or not doing? Do you get any error messages? I'll take a look, but it would be easier if you gave a bit more information :) |
As it's running through the for loop it's changing everything under /proj/* to the first group it gets assigned. WTF?
|
Hi,
This I can understand: # Set $GROUP Variable GROUP=`ls -ld $i | awk '{print $4}'`; But this seems to be unneeded, it always sets it to a group that it already is: # Set Project ROOT Group ownership chgrp $GROUP $i; The following could do something you didn't think of: # Set Project ROOT /proj/* to 2751 chmod 2751 $i; All files and directories in /proj/ (not recursive) will get 2751 as permission. Do you also want this to be true for files?? I don't seem to understand your problem: it's changing everything under /proj/* to the first group it gets assigned. If /proj/dirone has internet as group, all dirs and files under /proj/dirone will have internet as group after you run the script. Code:
Original filestructure: |
This is the completed script. basically it will create a list of directory names only and then chgrp rwx on directories and chgrp +rw on files so all group members will always have access to the files, then it extracts the group name of the root (This relies that the /proj/X group is correct) and applies that group ownership recursively throughout the directory structure for that instance of $GROUP, then does a final chmod 2751.
Code:
#!/bin/bash |
All times are GMT -5. The time now is 11:12 PM. |