tar: how to bundle the “extract to directory XXX”

2019-09-02 09:32发布

I know 'tar xf -C DIR' will untar the files in DIR, but is there an option to bundle the "-C DIR" information within the tarball when I create the tar file, so that when I use 'tar xf' the files will be automatically extracted into DIR?

Thanks.

标签: shell tar
1条回答
Animai°情兽
2楼-- · 2019-09-02 09:53

Create DIR, then symlink the files into DIR (no copying involved), then use GNU tar with the dereference (-h) option:

mkdir DIR
ln -s /path/to/f1 /path2/f2 DIR/
tar chf archive.tar DIR
rm -rf DIR

This will archive the actual files pointed by the symlinks (and not the symlinks you created temporarily)

Downside is you can't put actual symlinks in the archive, of course (they too will be dereferenced)

查看更多
登录 后发表回答