[UCLA-LUG] file uid stuff

Glenn Glazer gglazer@pic.ucla.edu
Thu, 17 Feb 2000 08:30:54 -0800


Two approches come to mind (btw, -user finds either username patterns or
UID (numeric patterns):

First is the more or less obvious use of find (I am assuming you are
running the command from the top directory you want to recurse down from):

find . -type f -user '<olduser_pattern>' -print | xargs chown <newuser>

The -type f part keeps this to 'regular' files - i.e., no FIFOs, doors, dev
files, etc.

However, find is a notoriously slow program, so you can try ls, which may
be faster.  If you use ls, then use -l if you are going for a username and
-ln if you are using the numeric forms.  Then, you would have something like:

ls -l{n}R | grep '<olduser_pattern>' | ls | xargs chown <newuser> 

The second ls command is to massage the input back into just file names -
chown won't understand the rest of the -l output.  If you are not using a
regexp in the olduser pattern, you can use fgrep instead of grep to speed
this up.

A fun thing to do might be to stick a | wc -l on the end to see how many
files you chowned.  Also, if you wind up trying both methods, I would be
interested in which ran faster over how many files and directories.

Best,

Glenn

P.S.  I've never used ispell - what is it for?  :)



At 02:48 AM 2/17/00 -0800, you wrote:
>anyone know anything you can us in if [ ... ] to check if the uid of a
>file matches a variable?   I'm trying to switch all the user ids on a
>bunch of disks to new ones and my current idea uses 'find ./ -user ...'
>for each disk and loops through each pair of old/new ids.  I know its
>going to be time consuming either way, but is it more efficient to go
>through case statements for each file or go through the file system for
>each case (i.e. recursion vs. iteration, sort of).  
>
>Any input is greatly apreciated.
>
>-justin
>
>p.s. I like ispell, I just don't use it enough
>
>
>_______________________________________________
>UCLALUG Linux mailing list - Linux@linux.ucla.edu
>http://linux.ucla.edu/mailman/listinfo/linux