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

Stuart Johnston saj at thecommune.net
Fri May 19 11:20:17 CDT 2006


Similar topics to this have been discussed on this list a number of 
times presenting a number of different solutions.  In the spirit of 
TMTOWTDI, you could also use:

The X permission in chmod ( execute only if the file is a directory or 
already has execute  permission  for  some user).

The -exec action on find.

The xargs command.

I like your solution too though and I'm glad you posted it because it 
taught me a new trick or two.  Sometimes one solution will work better 
than another in a particular situation so it is nice to know as many as 
possible.

-Stuart


Richard Geoffrion wrote:
> 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
> 
> 




More information about the Discuss mailing list