如何压缩目录,并将软链接转换为硬链接?

Abe*_*Abe 0 compression bash symlink rhel tar

我想压缩一个目录.

tar -cvzf mydir.tar.gz mydir
Run Code Online (Sandbox Code Playgroud)

但这会保留符号链接,因此无法移植到新系统.

如何转换符号链接?

我试过了

tar -cvzfh 
Run Code Online (Sandbox Code Playgroud)

自从man tar

-h, - dereference

          don’t dump symlinks; dump the files they point to
Run Code Online (Sandbox Code Playgroud)

但这会导致错误

tar: Error exit delayed from previous errors
Run Code Online (Sandbox Code Playgroud)

并创建一个名为"zh"的文件

我的文件位于RHEL服务器上.

Jan*_*lho 5

你的tar.gz文件名必须紧跟在-f标志之后,只是重新排序标志可能有效.

tar -cvzhf mydir.tar.gz mydir
Run Code Online (Sandbox Code Playgroud)