cleancut-fluent

(Answer) (Category) iSeries / AS400 FAQ : (Category) General :
How can I recursively change the owner of objects in the IFS?
Q. I want to change the owner for all the objects in the IFS and recurse
   into each subdirectory and change the ownership there as well.  What's
   a good way to do that, since CHGOWN doesn't recurse?

A. This is easy to do in QSHELL.   For example, to change everything in
   directory called /some/dir to be owned by klemscot:

   STRQSH
   find /some/dir -exec chown klemscot {} \;

   Or, maybe when one employee leaves and a new one starts you want to change
   ownership from one person to another:

   find . -user mike -exec chown klemscot {} \;

   (the . means it will work out of the current directory)

   In fact, you can have any QSHELL command be executed after the "-exec"
   keyword.  The {} is replaced with the name of the file when the command
   is executed, and the \; tells the find command that it's reached the end
   of the command string.

   So, if you wanted to remove write access to everything in a directory,
   you might do this:

   find /some/dir -exec chmod -w {} \;

   Or, of course, only take write access away from files who are owned by
   mike:

   find /some/dir -user mike -chmod -w {} \;

   So, the find utility is great for working on directories recursively.
   More info can be found in the information center:

   http://publib.boulder.ibm.com/iseries/v5r2/ic2924/info/rzahz/find.htm

Answer courtesy Scott Klement via Midrange-L
You can also submit this to batch with a construct like this:

sbmjob job(printdir) cmd(QSH CMD('ls -al')) jobq(qs36evoke)
David Morris and Martin Rowe add the idea that one can use the SYSTEM 
command instead of chown or chmod:

for autfil in $(find /dir/dir2 -name '*.extension'); 
  do system "chgaut obj('"$autfil"') objaut(*all)"; 
done
Here is the command I used to change the owner, set the authority list, and revoke public authority of all IFS files and directories in a folder. 

 QSH        CMD('for autfil in $(find /myfolder/*); do +
              system  "CHGOWN OBJ(''"$autfil"'') NEWOWN(MYNEWOWN)"; +
              system  "CHGAUT OBJ(''"$autfil"'') AUTL(MYAUTL)"; +
              system  "CHGAUT OBJ(''"$autfil"'') USER(*PUBLIC) +
                       DTAAUT(*AUTL) OBJAUT(*NONE)";
              done')

Please note, the more files there are the longer it will take to run. This update took about 4 hours to run on our 720 for about 25,000+ files and 700 directories. 
how about a simple
 chown -R [owner USRPRF] [filespec]

eg
 chown -R qsysopr /home/*
ans-ins-part
Append to This Answer
buck.calabro, mnwills, ben
Previous: (Answer) Screen Scraping, Re-facing, WebEnabling; Terminology 101
Next: (Answer) DST password!!
This document is: http://faq.midrange.com/index.pl?file=308
[Search] [Appearance]
This is a Faq-O-Matic 2.721.