compress with .tar.gz code example

Example 1: how to extract tar.gz

If your tar file is compressed using a gzip compressor, use the following command to extract it.

    $ tar xvzf file.tar.gz
    
If your tar file is compressed using a bZip2 compressor, use the following command to extract it.

    $ tar xvjf file.tar.bz2

Example 2: compress folder in tar.gz unix

#Compress a folder in tar.gz format
tar -zcvf final_archive.tar.gz folder_to_compress/

#Multicore compression using pigz (can be installed with: conda install -c anaconda pigz)
tar cf - ./folder_to_compress/ | pigz -9 -p NPROC > final_archive.tar.gz