工作生活中时常会遇到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 file
  • v - means verbose, or to list out the files it’s extracting
  • z - instructs tar to decompress the files – without this, you’d have a folder full of compressed files
  • f - 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 archive
  • v - verbose, meaning it lists the files it includes
  • z - signals tar to compress the files
  • f - specifies the name of the file

:这篇文章的内容主要来源于这篇文章。英文部分自己也尝试翻译过,但是还是觉得原文表达的意思更加准确,所以选择沿用。更详细的内容请访问原网址。