Linux provides gtar
command in order to compress and create tar files. If we are trying to tar a directory and within this directory, there will be a lot of sub-directories and files. We need to tar this directory with tar
format. We can use gtar
which is an alias of the tar
command to create tar archives.
Linux提供gtar
命令以压缩和创建tar文件。 如果我们尝试将目录压缩到该目录中,则该目录中将包含许多子目录和文件。 我们需要将该目录以tar
格式tar
。 我们可以使用gtar
它是tar
命令的别名)来创建tar归档文件。
为Ubuntu,Debian,Mint,Kali安装 (Install For Ubuntu, Debian, Mint, Kali)
We can install tar
command with the following command.
我们可以使用以下命令安装tar
命令。
$ sudo apt install tar

安装Fedora,RedHat,CentOS(Install Fedora, RedHat, CentOS)
We can install tar
for Fedora, RedHat, CentOS with dnf
or yum
command like below.
我们可以使用dnf
或yum
命令为Fedora,RedHat,CentOS安装tar
,如下所示。
$ sudo yum install tar
OR
要么
$ sudo dnf install tar
创建Tar存档 (Create Tar Archive)
We can create new tar
file by using cvf
options like below. We will provide the directory name or path and also provide the newly created archive file with .tar
extension. We will tar the directory with the nmap
to the nmap.tar
我们可以使用cvf
选项创建新的tar
文件。 我们将提供目录名称或路径,并提供新创建的扩展名为.tar
存档文件。 我们将带有nmap
的目录tar到nmap.tar
$ tar -cvf nmap.tar nmap

提取Tar存档(Extract Tar Archive)
We can extract a tar archive with the xvf
option like below. We will just provide the name of the tar archive which is nmap.tar
in this case.
我们可以使用xvf
选项提取tar存档,如下所示。 在这种情况下,我们仅提供tar存档的名称为nmap.tar
。
$ tar -xvf nmap.tar
用Gzip压缩Tar存档 (Compress Tar Archive with Gzip)
We can create a tar archive which is also compressed by using Gzip compression algorithm. We will just provide the -z
option to the default tar
creation options. We will create tar.gz
gzip compressed archive from the directory nmap
in this example.
我们可以创建一个tar归档文件,该归档文件也可以使用Gzip压缩算法进行压缩。 我们仅将-z
选项提供给默认的tar
创建选项。 在此示例中,我们将从目录nmap
创建tar.gz
gzip压缩存档。
$ tar cvzf nmap.tar.gz nmap

使用Bzip压缩Tar存档(Compress Tar Archive with Bzip)
Bzip is another compression algorithm which can be used to compress tar files to use less storage. We will provide extra -j
option to the xvf
like below.
Bzip是另一种压缩算法,可用于压缩tar文件以减少存储量。 我们将为xvf
提供额外的-j
选项,如下所示。
$ tar cvjf nmap.tar.bz nmap
翻译自: https://www.poftut.com/linux-gtar-command-tutorial-with-examples-and-compare-with-tar/