Skip to content

tar | Cheatsheet

The Linux “tar” stands for tape archive, which is used by a large number of Linux/Unix system administrators to deal with tape drive backup in Linux. The tar command is used to rip a collection of files and directories into a highly compressed archive file commonly called tarball or tar, gzip and bzip in Linux


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