While extracting a tgz file, I have noticed that the permission changes to something weird! The tgz file belongs to root:root however, the folder belongs to 502:games

[root@rocks7 common]# ls -l
-rw-r--r-- 1 root root 4779534 May  2  2012 scalapack-2.0.2.tgz
[root@rocks7 common]# tar xf scalapack-2.0.2.tgz
[root@rocks7 common]# 
[root@rocks7 common]# ls -l
total 98576
drwxr-xr-x 10  502 games     4096 May  2  2012 scalapack-2.0.2
-rw-r--r--  1 root root   4779534 May  2  2012 scalapack-2.0.2.tgz

What is the issue here?

  • 1
    consider gnu tar's --no-same-owner – Jeff Schaller Jul 19 '18 at 14:44

The tarball contains a scalapack-2.0.2 directory owned by user id 502 and whatever group id corresponds to the games group (or, perhaps, the games group by name). You can see this by running

tar tvf scalapack-2.0.2.tgz

Tar archives store ownership and permissions in addition to the file contents; since you’re extracting as root, that metadata is applied to the extracted files. The ownership of the tarball itself has no impact on the ownership of the extracted data.

Since you’re running CentOS, you’re presumably running GNU tar, and you can use the --no-same-owner and --no-same-permissions options to extract tarballs without applying the stored ownership and permissions. Other tar implementations may have similar options (e.g. -o on FreeBSD tar).

  • POSIX pax has the (standardized) option -p p (preserve only permissions) for that. – Jörg W Mittag Jul 19 '18 at 22:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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