Commands.page Logo

Tar Flag to Prevent Changing File Permissions in Ubuntu

This article provides a direct answer to managing archive extraction security within the Ubuntu operating system. It details the specific tar command flag used to stop the application of stored file permissions, ensuring that extracted files adhere to your current user settings instead of the archive’s original metadata.

The specific flag that prevents tar from changing file permissions upon extraction is --no-same-permissions. When you extract an archive, tar typically attempts to apply the exact permissions stored within the archive file. Using this flag instructs tar to ignore the archived permissions and apply your current user umask instead.

To use this flag, include it in your extraction command. For example, to extract a gzipped tar archive without changing file permissions, run the following command in your terminal:

tar --no-same-permissions -xzf archive.tar.gz

This option is particularly useful when extracting archives as the root user. By default, root extraction preserves original permissions, which can pose security risks if the archive contains files with overly permissive settings. Using --no-same-permissions ensures that extracted files remain secure according to your system’s default configuration.