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.
Install For Ubuntu, Debian, Mint, Kali
We can install
tar command with the following command.
$ sudo apt install tar
Install Fedora, RedHat, CentOS
We can install
tar for Fedora, RedHat, CentOS with
yum command like below.
$ sudo yum install tar
$ sudo dnf install 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
$ tar -cvf nmap.tar nmap
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.
$ tar -xvf nmap.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 cvzf nmap.tar.gz nmap
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.
$ tar cvjf nmap.tar.bz nmap