Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I would like to create a tar file with contents belonging to an owner:group pair who do not exist on the system from which the file is being made.

Here's the direction I've tried:

tar ca --owner='otherowner' --group='othergroup' mydata.tgz mydata

And when running this command, I get the following error:

tar: otherowner: Invalid owner
tar: Error is not recoverable: exiting now

Is there a way to force tar to accept the owner:group, even though neither of them exist on the system from which the file is being created?

share|improve this question

2 Answers 2

up vote 3 down vote accepted

Linux doesn't use internally owners and groups names but numbers - UIDs and GIDs. Users and groups names are mapped from contents of /etc/passwd and /etc/group files for convenience of user. Since you don't have 'otherowner' entry in any of those files, Linux doesn't actually know which UID and GID should be assigned to a file. Let's try to pass a number instead:

$ tar cf archive.tar test.c --owner=0 --group=0
$ tar -tvf archive.tar 
-rw-rw-r-- root/root        45 2013-01-10 15:06 test.c
$ tar cf archive.tar test.c --owner=543543 --group=543543
$ tar -tvf archive.tar 
-rw-rw-r-- 543543/543543    45 2013-01-10 15:06 test.c

It seems to work.

share|improve this answer
    
Interesting! So the tar command must be polling the system for the user and group numbers to match the names I was trying to use. Thanks! –  David Jan 14 '13 at 15:10
1  
A note for others coming across this: tar automatically outputs user/group names when using the -tvf flags. To view the current numbers for files in an archive use a command like this: $ tar --numeric-owner -tvf archive.tar –  David Jan 14 '13 at 15:23

Here is a piece of code to replace the user/group with ids on the fly:

tar ca --owner="$(id -u ***otherowner***)" --group="$(id -g ***othergroup***)" mydata.tgz mydata
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.