A common task on most modern operating systems is to combine and compress multiple files into a single file. This could be in order to store files on a smaller device, to make it easy to download files from a website, or to merge and compress files for email transport. This guide focuses on some of the more common Linux utilities that merge and compress files.
Tar
The purpose of the tar command, which stands for tape archive, is to merge multiple files into a single file. To create a tar file named sample.tar, execute the following
#tar -cf sample.tar <files_to_merge>
To list the contents of a .tar file:
#tar -tf sample.tar
To extract the contents of a .tar file:
#tar -xf sample.tar
d
gzip
Use the gzip command to compress files:
#gzip <filename>
To display percentage of compression,
#gzip -v <filename>
To decompress the file,
#gzip -d <filename>
Note that the gzip command replaces the original file with the smaller compressed file.
gunzip
Use the gunzip command to decompress gzipped files
#gunzip <filename>
bzip2
Use the bzip2 command to compress files:
#bzip2 <filename>
To Display percentage of compression.
#bzip2 -v <filename>
To Decompress the file
#bzip2 -d <filename>
Note that the bzip2 command replaces the original file with the compressed file.
Xz
Use the xz command to compress files:
#xz <filename>
You can use the unxz command to decompress the file
#unxz <filename>
To display percentage of compression,
#xz -v <filename>
You can also write output to STDOUT and do not replace the original file. Use redirection to place output data into a new file
#xz -c file2 > file2.xz
The gzip, xz, and bzip2 commands are very similar. The biggest difference is the technique used to compress files. The gzip command uses the Lempel-Ziv (LZ77) coding method, whereas the bzip2 command uses the Burrows-Wheeler (BWT) block-sorting text-compression algorithm and Huffman coding. The xz command uses the LZMA and LZMA2 compression methods.
Latest posts by Ruwantha Nissanka (see all)
- 4 ways to hide your identity using linux - January 18, 2021
- How To Install Kali Linux in Virtualbox - December 31, 2020
- Kali Linux : The OS That Hackers Use - December 31, 2020
- How to monitor user activity in Linux with Acct - December 30, 2020
- Debsecan : You will not miss another security update - December 28, 2020