【问题标题】:extracting specific dir from tar file without creating the containing hierarchy从 tar 文件中提取特定目录而不创建包含层次结构
【发布时间】:2014-02-19 08:34:26
【问题描述】:

假设一个 tar 文件具有以下布局

$ tar -xvf test.tar -C test ./one/two/three

./one/two/three/
./one/two/three/four/
./one/two/three/four/file00.txt
./one/two/three/four/file01.txt
./one/two/three/four/file02.txt
./one/two/three/four/file03.txt
./one/two/three/four/file04.txt
./one/two/three/four/file05.txt

是否可以只提取名为“four”的目录,并且它的内容是指定的目录。 但是目录 four 应该在提到的输出目录的直接位置。

$ tar -xvf test.tar -C test one/two/three

我已尝试上述方法,但输出目录 test 包含目录四的所有文件夹层次结构。

【问题讨论】:

  • 不可能一蹴而就;您需要mv 所需的目录。
  • 是的,我也这么认为...

标签: linux bash shell tar


【解决方案1】:

您是否考虑过使用 tardy 预处理您的 tar 存档?

【讨论】:

  • 不,事实上我第一次听说迟到。
【解决方案2】:

这应该只用于提取./one/two/three/four/ 目录:

tar -xvf test.tar ./one/two/three/four/

【讨论】:

  • 我希望目标目录应该包含四个直接级别而不是 ./one/two/three/four
  • 因为你原来的路径本身就是./one/two/three/four/。如果你愿意,你可以在满足你的需要之后执行mv 命令。
  • 是的,但我想知道 tar 是否也有这个选项!
  • 我认为没有 tar 内置选项可以这样做。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-11-04
  • 1970-01-01
  • 2018-04-17
  • 2013-10-03
  • 1970-01-01
  • 2019-12-28
  • 2017-09-20
相关资源
最近更新 更多