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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am running this command:

$ sudo tar xvzf nexus-latest-bundle.tar.gz

The extracted files belong to an unknown (1001) user:

drwxr-xr-x 8     1001     1001      4096 Dec 16 18:37 nexus-2.12.0-01
drwxr-xr-x 3     1001     1001      4096 Dec 16 18:47 sonatype-work

Shouldn't it be root the owner under a normal configuration?

I am working on a linux installation replicated from an AWS AMI.

share|improve this question
up vote 4 down vote accepted

When extracting files as root, tar will use the original ownership. You can override that using the --no-same-owner option (alternatively, -o).

Your tar file referred to user/group which do not exist on the system where you extracted it.

If you extract files as yourself (a non-privileged user), you can only create files owned by yourself.

The GNU tar manual says:

--same-owner
When extracting an archive, tar will attempt to preserve the owner specified in the tar archive with this option present. This is the default behavior for the superuser; this option has an effect only for ordinary users. See section Handling File Attributes.

share|improve this answer
    
Ok so this happens only when being root, because if I run the command without sudo: 'tar xzvf nexus-latest-bundle.tar.gz' then the ownership is set to my current user, is that an expected behavior? – raspacorp Feb 19 at 23:52
1  
@raspacorp: As a non-root user, you don't have the authority to create files with any ownership other than your own. So by necessity, the files get created with you as the owner. – Nate Eldredge Feb 20 at 4:21

The person who created the tar file had an effective user ID and group ID (UID:GID) of 1001:1001. Since tar, by default, preserves the ownerships and permissions, when you expand it, you inherit these values. If you have a user with UID:GID 1001:1001 on your system, these files would have been owned by that user.

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.