6/23/08 Recursively changing ownership on an IFS directory and all the files stored within it

This function needs to be run in STRQSH.

In order to change the owner of all files and directories recursively run the following command:

for eachFile in $(find /directoryToChangeOwner -name '*');

do system "CHGOWN OBJ('"$eachFile"') NEWOWN(userProfile)";done

Note: Replace values in parenthesis with appropriate values.



Disclaimer: Vision Solutions makes every effort to provide accurate system management information and programming code; however the company cannot be held liable for the accuracy of information nor its compatibility in your own environment. Please review and test thoroughly before implementing. © Copyright 2008, Vision Solutions, Inc. All rights reserved. IBM, System i, iSeries, and AS/400 are trademarks of International Business Machines Corporation. All other brands are property of their respective registered owners.

4 comments:

Chris S said...
This comment has been removed by the author.
Chris S said...

Or you can run this on a command line:

CHGOWN OBJ('directoryToChangeOwner/*') NEWOWN(newOwner)

Vision Solutions said...

Thank you for your feedback concerning this blog entry. If we were looking at simply changing the ownership of all files and directories within a single directory then your suggestion is more succinct and should actually finish the process faster. However, using the CHGOWN command with the asterisk in the way you suggest would change, for example, "/home/chris/*" but it would not change the content of any directories within "/home/chris". The function we have suggested above would change the ownership of "/home/chris/*/*/*/*/*" recursively, regardless of the number of levels of directory structure you have on your file system.

Unknown said...

Or, from QSH, issue "chown -R newOwner directoryToChangeOwner".