How to compress a symbolic link?

krifur picture krifur · Feb 22, 2011 · Viewed 21.4k times · Source

With tar, I tried to compress a repository in a chroot environment with ssh, but it failed as it just compressed the symbolic link itself.

How can I compress its content?

-bash-3.00$ ls -ail
1263583 lrwxrwxrwx  1 root     root       18 Apr 18  2008 mainwebsite_html -> ../../var/www/html

-bash-3.00$ tar -cjvf archive.tar.bz2 mainwebsite_html

-bash-3.00$ ls -ail
7509101 -rw-r--r--  1 user1 user1  136 Feb 22 08:57 archive.tar.bz2
1263583 lrwxrwxrwx  1 root     root       18 Apr 18  2008 mainwebsite_html -> ../../var/www/html

Answer

Ignacio Vazquez-Abrams picture Ignacio Vazquez-Abrams · Feb 22, 2011

From the tar(1) man page:

  -h, --dereference
          follow symlinks; archive and dump the files they point to