Skip to content
Latchkey

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

Terminal
tar -xpf archive.tar
sudo tar -xpf app.tar -C /opt          # root preserves perms anyway
tar -xf archive.tar --no-same-permissions   # apply umask instead

Options

FlagWhat it does
-p / --preserve-permissionsRestore stored modes, ignore umask
--same-permissionsAlias for -p
--no-same-permissionsSubtract the umask from stored modes
-c create -pOn 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.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →