tar:如何捆绑“解压到目录 XXX";tar 文件中的信息 [英] tar: how to bundle the "extract to directory XXX" info inside a tar file

查看:53
本文介绍了tar:如何捆绑“解压到目录 XXX";tar 文件中的信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道 'tar xf -C DIR' 会解压 DIR 中的文件,但是当我创建 tar 文件时,是否有一个选项可以将-C DIR"信息捆绑在 tarball 中,以便当我使用 'tarxf'文件会自动解压到DIR吗?

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?

谢谢.

推荐答案

创建 DIR,然后将文件符号链接到 DIR(不涉及复制),然后使用带有取消引用 (-h) 的 GNU tar选项:

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)

这篇关于tar:如何捆绑“解压到目录 XXX";tar 文件中的信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆