From man 1 tar
:
[...]
-p, --preserve-permissions, --same-permissions
extract information about file permissions (default for superuser)
[...]
--no-same-permissions
apply the user's umask when extracting permissions from the archive
(default for ordinary users)
[...]
From this I understand that by default extracted files' permissions are set based on the user's umask, unless the user is root:
% umask
002
So files extracted by me should have permissions 664
(666
-002
).
However:
% touch foo
% chmod +x foo
% ls -l
total 0
-rwxrwxr-x 1 user user 0 nov 3 19:36 foo
% tar cf foo.tar foo
% rm foo
% tar xf foo.tar
% ls -l
total 12
-rwxrwxr-x 1 user user 0 nov 3 19:36 foo
-rw-rw-r-- 1 user user 10240 nov 3 19:36 foo.tar
I.e., Tar is preserving the permissions of the original file even though I didn't pass the -p
, --preserve-permissions
or --same-permissions
switch.
Nonetheless if I pass the --no-same-permissions
switch:
% tar xf foo.tar --no-same-permissions
% ls -l
total 12
-rwxrwxr-x 1 user user 0 nov 3 19:36 foo
-rw-rw-r-- 1 user user 10240 nov 3 19:36 foo.tar
Still Tar is preserving the permissions of the original file.
Can someone please explain why is that?
Since adonis (who spotted the problem) didn't post an answer yet, I'll post an answer myself.
This, contrarily to what I thought, means that the umask is applied to the permissions of the folders / files in the archive, and not to the conventional permissions of newly created folders / files (
777
/666
) like I thought.I.e. a folder / file extracted without passing the
-p
,--preserve-permissions
or--same-permissions
switch won't have the permissions set to777 & ~umask
/666 & ~umask
, but tofolder's/file's_archived_permissions & ~umask
.In this specific case I was additionally fooled by the fact that applying an umask of
002
to a file with permissions775
doesn't change anything, since775 & ~002 = 775
.So, in short, extracting a file with permissions
775
with an user umask of002
produces, correctly, a file with permissions775
, result of775 & ~002
.