开发者

Bash tar append file

开发者 https://www.devze.com 2023-02-26 01:58 出处:网络
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

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

精彩评论

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

关注公众号