tar -p: Preserve Permissions (Usage & CI Errors)
tar -p restores the exact permission bits stored in the archive.
Permissions decide whether an extracted binary is executable or a secret file is readable. The -p flag and your umask together control what the unpacked tree looks like.
What it does
tar -p (--preserve-permissions, also --same-permissions) sets extracted files to the exact mode stored in the archive, ignoring the current umask. When run as root, GNU tar preserves permissions by default; for non-root users you must pass -p to get the stored bits instead of umask-filtered ones.
Common usage
tar -xpf archive.tar
sudo tar -xpf app.tar -C /opt # root preserves perms anyway
tar -xf archive.tar --no-same-permissions # apply umask insteadOptions
| Flag | What it does |
|---|---|
| -p / --preserve-permissions | Restore stored modes, ignore umask |
| --same-permissions | Alias for -p |
| --no-same-permissions | Subtract the umask from stored modes |
| -c create -p | On create, store extended attributes/ACLs (GNU) |
Common errors in CI
tar: ./file: Cannot change mode to rwxr-xr-x: Operation not permitted appears when extracting into a filesystem or container that disallows the chmod (or as a user without rights). It is usually a warning, but it can trip tar: Exiting with failure status due to previous errors. If you do not need exact modes, extract with --no-same-permissions to avoid the failing chmod.