tar: how to bundle the “extract to directory XXX” info inside a tar file

笑着哭i 提交于 2019-12-13 05:30:41

问题


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.


回答1:


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)



来源:https://stackoverflow.com/questions/20050824/tar-how-to-bundle-the-extract-to-directory-xxx-info-inside-a-tar-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!