How can I tar ball a directory hierarchy with soft links in linux

GNU tar normally includes symlinks in the tarball it generates. If you want it to include the file the symlink points to instead then pass it -h/--dereference when creating the tarball.


When used with standard arguments tar xvf, the soft links are saved in the tar archive as soft-links.  Then there are two cases:

  • If your symlink is a full pathname, it might be broken when untarred.
  • If your symlink is a relative pathname, under the folder you are tarring, it will work fine when extracted.

If you want to tar the file and not the symlink, you can use the -h / --dereference arguments.