Change user id and group id ownership of files within a tarball

tarusers

I have a tarball and the files it contains do not have the right user and group ownership. Files are owned jenkins:jenkins and I'd like them to be owned naftuli:othergroup.

Is there a way for me to edit the tarball in place so that the files it contains become owned by naftuli:othergroup?

The problem I'm facing is that at the time of the tarball creation, the jenkins user doesn't have permissions to chown things to different users and groups. At the time of extraction, I will have permissions to create those files as the users mentioned, so I need to edit the user ids and group ids within the tarball.

Best Answer

Archive::Tar or similar software would be one method.

% touch foo  
% tar cvf x foo
foo
% tar tvf x          
-rw-rw-r--  1 jdoe12   jdoe12           0 May  6 20:36 foo
% perl -MArchive::Tar -e '$t=Archive::Tar->new;$t->read("x");$t->chown("foo","root");$t->write("y")'
% tar tvf y
-rw-rw-r--  1 root     jdoe12           0 May  6 20:36 foo
% 
Related Question