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

asked 12 Sep '11, 07:48

Jake's gravatar image

Jake ♦♦
796222226235
accept rate: 98%


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

answered 12 Sep '11, 07:50

Jake's gravatar image

Jake ♦♦
796222226235
accept rate: 98%

How can I recursively change the owner and group of a directory in Linux/Unix?

(05 Jun '12, 03:06) laiyongyong

I agree, it would be nice to recursively change ownership/group. The only way I've found is to use <runprogram> with chown -R. Is there another way?

(09 Jun '12, 03:26) tahoar

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

answered 14 Jun '12, 04:15

juanjo's gravatar image

juanjo ♦♦
5.8k413
accept rate: 23%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×29
×10
×8
×7

Asked: 12 Sep '11, 07:48

Seen: 3,893 times

Last updated: 14 Jun '12, 04:15