Which Flag Prevents Tar From Dereferencing Symbolic Links
This article provides a concise answer regarding the tar command utility within the Ubuntu Linux operating system, specifically focusing on how to handle symbolic links during archive creation. It outlines the exact flag required to ensure that symbolic links are preserved as links rather than being replaced by the files they reference, helping users maintain accurate directory structures in their backups.
The specific flag that prevents tar from dereferencing symbolic links
is --no-dereference. When you run the tar command on
Ubuntu, using this option ensures that the archive stores the symbolic
link itself instead of copying the target file’s data. This is critical
when you need to preserve the exact structure of a filesystem without
inflating the archive size with duplicate data from linked files.
To use this flag, include it in your command string before specifying
the file or directory you wish to archive. For example, the command
tar --no-dereference -cvf backup.tar /home/user/data will
create an archive named backup.tar while keeping all symbolic links
intact. It is important to note that GNU tar, which is the default
version on Ubuntu, does not dereference links by default unless the
-h or --dereference flag is explicitly used.
However, adding --no-dereference makes your intention
explicit and ensures consistent behavior across different scripts or
configurations.