I need to change the owner and group of a file or directory in Unix. How do I do this?

Answered

Comments

2 comments

  • Avatar
    Jake

    You can change the owner and group of a file or directory using a <changeOwnerAndGroup> action. Because these changes require administrative privileges, you will need to require installation by the administrator. You will have to include a section like the one below inside an action list section of your XML installer project file.

           <changeOwnerAndGroup>
               <files>*/somefile.conf;*/var/somefile</files>
               <owner>nobody</owner>
               <group>nobody</group>
           </changeOwnerAndGroup>
    
  • Avatar
    juanjo

    The <changeOwnerAndGroup> is not recursive by default. If you need to make it recursive and to apply it to files being unpacked, you can place it in the <folder> containing the files:

    <folder>
       <name>sample</name>
       <distributionFileList>
           <!-- List of files that need changing the owner and group -->
       </distributionFileList>
       <actionList>
           <changeOwnerAndGroup>
               <files>*/somefile.conf;*/var/somefile</files>
               <owner>nobody</owner>
               <group>nobody</group>
           </changeOwnerAndGroup>
       </actionList>
    </folder>
    

    It will match the patterns recursively to all the packed files.

    Another solution, if you want to apply recursively but not to the files packed in a folder, is to use a multidepth pattern:

       <changeOwnerAndGroup>
           <files>{*,*/*,*/*/*,*/*/*/*,*/*/*/*/*,*/*/*/*/*/*}.conf;{*,*/*,*/*/*,*/*/*/*,*/*/*/*/*,*/*/*/*/*/*}.txt</files>
           <owner>nobody</owner>
           <group>nobody</group>
       </changeOwnerAndGroup>
    

Please sign in to leave a comment.