

tar.xz archive located in ‘~/Documents’, to a certain directory (/var/-C /var/www/wordpressĮxample 5: If the archive file contains the absolute locations, such as /var/www/wordpress/all-the-files.

tar.bz2 archive to current directory, and preserve old files untouched, use command with -skip-old-files parameter: tar -skip-old-files -jxf 2Įxample 4: To extract. tar -no-overwrite-dir -Jxf Įxample 3: To extract. tar.xz to current directory and preserve the metadata of existing folder. For nonempty folder can not be removed, it normally overwrites its metadata.Įxample 2: To preserve the metadata of such a directory, use -no-overwrite-dir. If files to be extracted already exist in destination, it will replace them by removing the files before extracting. tar.gz archive to current directory: tar zxf To decompress files, use x (meaning extract archive) parameters instead of c in tar command.Įxample 1: extract a. To specify compression level for xz archive: XZ_OPT=-9 tar cfJ ~/ /var//var/www/wordpress Decompress gzip, xz, bzip2 archives To specify compression level for gzip archive (change number accordingly): GZIP=-9 tar -zcf /var/www/wordpress/ Number 1 meaning fast and lower compression level, which 9 meaning slow but even smaller compressed size. Tar command supports compression level from 1 to 9. Or, compress to lzop archive via: tar cf -lzop /var/www/wordpress/ Change Compression Level To compress to lzma archive, use command: tar cf -lzma /var/www/wordpress/ tar.lz file and save in current directory: tar cf -lzip /var/www/wordpress/ This command will compress all files under ‘wordpress’ into a bzip2 archive in user home, but exclude the absolute locations (/var/in command also exclude the ‘.’ directory as screenshot shows you:Įxample 4: In case you want to use lzip file archive, use command to compress ‘wordpress’ folder into. If you don’t want to see this output, add -P parameter in command, so it will be: tar cfJP ~/ /var/www/wordpress/Įxample 3: Though the best choice is first navigating to ‘wordpress’ directory in the case and then do compress process: cd /var/./ This command will output “ tar: Removing leading `/' from member names” during the process, which is a feature but not error! And, the archive will keep the absolute locations as you can see via the screenshot below: tar.gz archive, use command: tar -zcf *Įxample 2: compress all files under ‘/var/file and save it into user’s home folder. f – specify archive filename (required)Įxample 1: to compress all files in current directory and save it into a.The following parameters are mostly used when compressing files: And, Bzip2 is always available for choice. In short, use gzip for the fast speed but xz if you care more about output size. To decompress data, gzip is the fastest while xz do the second. tar.bz2) is in the middle for both speed and compressed size. tar.xz) takes longer time but has smaller size. tar.gz) does the things with less time but causes larger file size. They are the most popular file archive types to group a bunch of files with their directory structure preserved, but using different compression algorithms.
#Tar compress bz2 how to#
If you’re new to this thing or always forget how to use the parameters, then this tutorial is for, vs. Compress and extract data via tar command is one of the most basic skill for Linux administrators.
