开发者

Bash tar append file

How to append file to tar, e.g. file located in /usr/file.txt?

I want to append it in tar to var/file.txt for future extract it into [tar location]/var/file.txt instead of [tar location]/usr/file.txt, using the

tar --append --file foo.tar bar

Is it possible to put file in tar this way without replacing /usr/file.开发者_JS百科txt to /var/file.txt before archiving?


If you're using GNU tar, there's a --transform option for that, which takes a sed-like expression as argument:

tar --append --file foo.tar --transform='s,^usr/,var/,' /usr/file.txt


The only way I can think of is to use a symlink var/file.txt -> /usr/file.txt.

mkdir var && ln -s /usr/file.txt var
tar --dereference --append --file foo.tar var
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜