Modify file ownership for files inside tar archive

filespermissionstar

I am working as user, and I would like to create a tar archive, which when unpacked (by root) will extract its files with root ownership (otherwise root would have to change the ownership manually for each file, after the files have been extracted to its destination).

I have found fakeroot which seems to do exactly that. But i am not able to find the syntax which I need to use to create my archive.

How can I create a tar.xz archive, so that the files have root ownership when unpacked by root?

do something with fakeroot ...
tar cfpJ foo.tar.xz foo/

Best Answer

How can I create a tar.xz archive, so that the files have root ownership when unpacked by root?

That's up to the root who unpacks:

tar --no-same-owner -xf ...

If you want to make them all root to start with, you can use

tar --owner=root --group=root -cf ...
Related Question