bash 如何轻松提取嵌套的 tar.gz 文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2778153/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to extract nested tar.gz files easily?
提问by StarCub
I need to extract tar.gz a file. It's about 950mb. It has another 23 tar.gz files in it. Each of those 23 tar.gz files has one tar file in them. My questions is how I can easily extract all of them? Is there a commandline tool that I can use?
我需要提取 tar.gz 文件。大约 950MB。它还有另外 23 个 tar.gz 文件。这 23 个 tar.gz 文件中的每一个都有一个 tar 文件。我的问题是如何轻松提取所有这些?有我可以使用的命令行工具吗?
The structure is like the following:
结构如下:
foo.tar.gz
├───bar1.tar.gz
│ ├───foobar1.tar
├───bar2.tar.gz
│ ├───foobar2.tar
├───bar3.tar.gz
│ ├───foobar3.tar
├───bar4.tar.gz
│ ├───foobar4.tar
├───bar5.tar.gz
│ ├───foobar5.tar
├───bar6.tar.gz
│ ├───foobar6.tar
| ..........
| ..........
| ..........
| 23 of them
Thanks in advance.
提前致谢。
回答by phobozad
You can use the --to-commandargument to pass each extracted file to another program (on stdin). In this case, you pass it to another tar instance reading data from stdin.
您可以使用--to-command参数将每个提取的文件传递给另一个程序(在标准输入上)。在这种情况下,您将它传递给另一个从 stdin 读取数据的 tar 实例。
tar --to-command='tar -xzvf -' -xzvf foo.tar.gz
回答by StarCub
I ended up manually extracted foo.tar.gz and using the following shell script to extract those bar*.tar.gz files.
我最终手动提取了 foo.tar.gz 并使用以下 shell 脚本来提取那些 bar*.tar.gz 文件。
#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
for next in *.tar.gz
do
echo "Untaring - $next"
tar -xzf $next -C ~/foo
done
exit 0
hope this will help someone.
希望这会帮助某人。
回答by David Wolever
Yup.
是的。
tar -xzOf foo.tar.gz bar1.tar.gz | tar -xO foobar1.tar
Should do the trick.
应该做的伎俩。

