Linux gtar Command Tutorial with Examples and Compare with Tar – POFTUT

Linux gtar Command Tutorial with Examples and Compare with Tar


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.

Install For Ubuntu, Debian, Mint, Kali

We can install tar command with the following command.

$ sudo apt install tar
Install For Ubuntu, Debian, Mint, Kali
Install For Ubuntu, Debian, Mint, Kali

Install Fedora, RedHat, CentOS

We can install tar for Fedora, RedHat, CentOS with dnf or yum command like below.

$ sudo yum install tar

OR

$ 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 nmap.tar

$ tar -cvf nmap.tar nmap
Create Tar Archive
Create Tar Archive

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 Gzip
Compress Tar Archive with Gzip

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

LEARN MORE  Linux tar Command and How To Tar A Directory

Leave a Comment