Skip to content

Efficient Compression and Archiving with tar Command

Unlock the full potential of the tar command for efficient compression and archiving of your files and directories. Discover how to compress with maximum compression using Gzip or XZ, create archives with different compression levels, utilize multi-core processing for faster compression, and more. Streamline your file management workflows with these advanced tar command usages.


Compress with max compression

env GZIP=-9 tar cvzf file.tar.gz /path/to/directory                                    

Use Gzip instead of tar

tar -cvf files.tar /path/to/file0 /path/to/file1; gzip -9 files.tar                   

Create xz archive

XZ_OPT=-9 tar -Jcvf file.tar.xz /path/to/directory                                     

Create a gzip archive

tar cv /path/to/directory | gzip --best > file.tar.g                                  

Create xz with max compression

tar cv path/to/data | xz -9 > file.tar.xz                                              

Create gzip with multi cores

tar cf - paths-to-archive | pigz -9 -p 32 > archive.tar.gz                             

Compress multiple folders

for folders in ./*; 
    tar cv $folders|xz -9 > $folders.tar.gz; 
done                     

Compress with pigz

tar --use-compress-program="pigz --best --recursive" -cf archive.tar.gz YourData       

Fastest extraction

tar -I pigz -xf /mnt/sd/current/backup/bigbackup_web.tar.gz -C /tmp