user663896
user663896

Reputation:

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.txt to /var/file.txt before archiving?

Upvotes: 1

Views: 2942

Answers (2)

Idelic
Idelic

Reputation: 15582

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

Upvotes: 2

dogbane
dogbane

Reputation: 274612

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

Upvotes: 0

Related Questions