Handle tar.gz file
工作生活中时常会遇到xxx.tar.gz
这样的文件,每次都是现查现用,这样不好,所以
在此记录下来。
tar.gz
的介绍:
A tar.gz file contains several compressed files to save storage space, as well as bandwidth during the downloading process. The .tar file acts as a portable container for other files and is sometimes called a tarball. The .gz part of the extension, stands for gzip, a commonly-used compression utility.
在遇到file.tar.gz
后,用tar
命令去解压它:
$ tar -xvzf file.tar.gz
-xvzf
分别代表:
x
- instructs tar to extract the files from the zipped filev
- means verbose, or to list out the files it’s extractingz
- instructs tar to decompress the files – without this, you’d have a folder full of compressed filesf
- tells tar the filename you want it to work on
如果需要在解压前,查看压缩文件中包含的内容,则运行如下命令:
$ tar -tzf file.tar.gz
如果需要定义解压后文件的存放目录,则执行:
$ tar -xvzf file.tar.gz -C /specified/path
反过来,用如下命令可以创建一个tar.gz
文件:
$ tar -cvzf dir.tar.gz ./dir
c
- creates a new archivev
- verbose, meaning it lists the files it includesz
- signals tar to compress the filesf
- specifies the name of the file
注:这篇文章的内容主要来源于这篇文章。英文部分自己也尝试翻译过,但是还是觉得原文表达的意思更加准确,所以选择沿用。更详细的内容请访问原网址。