[NTLUG:Discuss] fixing/managing file rights - samba

Richard Geoffrion ntlug at rain4us.net
Fri May 19 10:55:14 CDT 2006


In light of the next meeting topic, I thought this was both relevant AND 
cool enough to share.

----

Today I got to, once again, deal with the evil EVIL spaces in directory 
names brought to me by MS Windows / SAMBA clients.  To be sure Mac OSX 
clients have their issues too (use the 2.x version of Netatalk to break 
the 31 char file name limit), but the majority of issues come from the 
more popular samba.

The issue today was getting a group of users to use a new shared 
directory.  After moving all of the files into the new location there 
was the need to change the user and group owners and set all of the file 
rights.   The chown -R user.group command was simple enough, but I 
didn't feel like chmod-ing the entire subdirectory structure to 2770.  
Since there are no reasons why files should be marked executable I 
decided to use 'find' to chmod the directories to 2770 and the files to 
2660.   The catch was that spaces in the file and directory names 
prevented an easy....

chmod 2770 `find -type d` ; chmod 2660 `find -type f`

If you ever find yourself in the need to do some surgical file 
maintenance, you might trying using the syntax...

find (insert your options) | while read X ; \
 do (Insert your command here) "$X" ; done

My commands turned out to be,

# find . -type d | while read X ; do chmod 2770 "$X" ; done
# find . -type f | while read X ; do chmod 2660 "$X" ; done

Note: I put quote marks around $X so that I could encompass those space 
filled directory names.

Another use I've put this to...

#Set a new owner to be the owner of any unowned files in this directory
 find . -type f -nouser | while read X; do chown bob "$X" ; done


-- 
Richard



More information about the Discuss mailing list