Linux 使用单个命令打开 .tar.gz 文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/651018/
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
Opening a .tar.gz file with a single command
提问by flybywire
When I download a .tar.gz file, I open it with two commands, first gunzip
and then tar
.
当我下载一个.tar.gz文件,我有两个命令,首先打开它gunzip
,然后tar
。
Is it possible to open it with just one command?
是否可以只用一个命令打开它?
采纳答案by unwind
tar xzf file.tar.gz
The letters are:
这些字母是:
- x - extract
- z - gunzip the input
- f - Read from a file, not stdin
- x - 提取物
- z - gunzip 输入
- f - 从文件中读取,而不是标准输入
回答by WiseTechi
You can use tar with a "z" argument
您可以使用带有“z”参数的 tar
tar xvfz mytar.tar.gz
回答by Martin Beckett
If you don't have gnu tar it is still possible to open the file in a single step (although technically still two commands) using a pipe
如果您没有 gnu tar,仍然可以使用管道一步打开文件(尽管技术上仍然是两个命令)
zcat file.tar.gz |tar x
回答by Espen
The only thing that I would add is that z usually only works on gnu tar. The typical UNIX tar won't have this in my experience at least. – Jon Mar 16 at 16:19
我唯一要补充的是 z 通常只适用于 gnu tar。至少根据我的经验,典型的 UNIX tar 不会有这个。– 乔恩 3 月 16 日 16:19
The z option works well on my OS-X 10.5 as well.
z 选项也适用于我的 OS-X 10.5。
When it comes to memorizing, I think it′s easy to think of what you want and not just some letters.
说到记忆,我认为很容易想到你想要什么,而不仅仅是一些字母。
- If you want to create an archive, then c will be the first option, else x will be the first option if you want to extract.
- If you want to compress/decompress with the gzip/gunzip program, then the next option should be z for zip. (All archives ending with .gz must be unzipped with the z option)
- The last mandatory option is f for the file.
- 如果你想çreate归档,那么C将成为第一个选项,如果要通过电子邮件否则x将是第一个选项X道。
- 如果你想用 g zip/gun zip 程序压缩/解压,那么下一个选项应该是 z for zip。(所有以 .gz 结尾的档案必须用 z 选项解压)
- 文件的最后一个强制选项是 f。
Then you usually end up with these two commands:
然后你通常会得到这两个命令:
- tar czf file.tar.gz /folder_to_archive/*
- tar xzf file.tar.gz
- tar czf file.tar.gz /folder_to_archive/*
- tar xzf 文件.tar.gz
回答by senthil
On Windows Try the tartool utility http://tartool.codeplex.com/
在 Windows 上尝试使用 tartool 实用程序http://tartool.codeplex.com/
Its free and the code is open source and uses SharpZipLib library.
它是免费的,代码是开源的,并使用 SharpZipLib 库。
Disclaimer : I am the author of this utility.
免责声明:我是此实用程序的作者。
回答by Shanewaj
How do I extract a gz file?
如何解压.gz文件?
Use guzip command as follows:
使用 guzip 命令如下:
$ gunzip file.gz
OR
或者
$ gzip -d file.gz
How do I extract a tar.gz or .tgz file?
如何提取 tar.gz 或 .tgz 文件?
Files with extension tar.gz or .tgz are tar files compressed with gzip. On Unix system extract them with following command:
扩展名为 tar.gz 或 .tgz 的文件是用 gzip 压缩的 tar 文件。在 Unix 系统上使用以下命令提取它们:
$ gunzip < file.tar.gz | tar xvf -
$ gunzip < file.tgz | tar xvf -
If you have GNU tar (Linux system) you can use the z option directly:
如果你有 GNU tar(Linux 系统),你可以直接使用 z 选项:
$ tar xvzf file.tar.gz
$ tar xvzf file.tgz
To read more go to http://www.cyberciti.biz/faq/howto-compress-expand-gz-files/
要阅读更多信息,请访问http://www.cyberciti.biz/faq/howto-compress-expand-gz-files/
回答by Sandeep Singh
Untar Single file from tar File compressed file
从 tar 文件解压单个文件
To extract a single file called video.mpeg from video.tar use the following command as given below example.
要从 video.tar 中提取名为 video.mpeg 的单个文件,请使用以下示例中给出的以下命令。
# tar -xvf video.tar video.mpeg
video.mpeg
视频.mpeg
Extracting Single file from tar.gz File
从 tar.gz 文件中提取单个文件
Use the following command to extract a single file codefile.xml from websitecode.tar.gz archive file
使用以下命令从 websitecode.tar.gz 存档文件中提取单个文件 codefile.xml
# tar -zxvf websitecode.tar.gz code.xml
code.xml
代码.xml
Extracting Single file from tar.bz2 File
从 tar.bz2 文件中提取单个文件
Use the command to extract single file file.html from websitecode.tar.bz2
使用命令从 websitecode.tar.bz2 中提取单个文件 file.html
# tar -jxvfwebsitecode.tar.bz2 home/website/file.html
/home/website/file.html
/home/website/file.html
Also you can read more about all the tar commands at This link explains all the useful tar commands available in linux
您也可以在此链接中阅读有关所有 tar 命令的更多信息,该链接解释了 linux 中可用的所有有用的 tar 命令