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 |
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. |