我能找到的最接近的是--transform选项。我不确定,但我猜这是一个仅限 GNU 的标志:
--transform, --xform EXPRESSION
use sed replace EXPRESSION to transform file names
Run Code Online (Sandbox Code Playgroud)
使用它,您可以传递sed替换命令并将其更改/为/abc:
tar cf root.tgz --transform 's/^\//\/abc/' /
Run Code Online (Sandbox Code Playgroud)
这将/在创建存档时仍然打印路径,但/abc在您提取它时它们会变成。
另一种方法,如果您tar没有--transform选择是制作/abc一个符号链接/,然后指向它:
$ ln -s / /abc
$ tar chf root.tgz /abc
Run Code Online (Sandbox Code Playgroud)
这-h是必不可少的,因为这告诉您tar要遵循链接:
-h, --dereference
follow symlinks; archive and dump the files they point to
Run Code Online (Sandbox Code Playgroud)
这将具有设置/abc为顶级目录的效果。
| 归档时间: |
|
| 查看次数: |
7843 次 |
| 最近记录: |