如何压缩符号链接?

kri*_*fur 22 linux command-line tar

我尝试使用ssh在chroot环境中使用tar压缩tar,但它失败了,因为它只是压缩符号链接本身,我如何压缩它的内容?

-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
Run Code Online (Sandbox Code Playgroud)

谢谢

Ign*_*ams 27

tar(1)手册页:

  -h, --dereference
          follow symlinks; archive and dump the files they point to
Run Code Online (Sandbox Code Playgroud)

  • 我的不好,我会在雨下跑3个小时!无论如何 (2认同)

Mar*_*bad 19

注意将"h"选项放在正确的位置.在你的例子中:

tar -cjvf archive.tar.bz2 mainwebsite_html
Run Code Online (Sandbox Code Playgroud)

应该

tar -chjvf archive.tar.bz2 mainwebsite_html
Run Code Online (Sandbox Code Playgroud)

  • 好决定; 很容易忘记 -f 实际上需要一个参数;) (2认同)