Most of us are probably familiar with the .zip or .rar type of data compression. The .zip ulitlity is often used in Windows. Usually in Linux to install a new piece of software or system firmware, files downloaded are usually compressed or combined together with a .tar extension, which makes them easier to download, since it’s one smaller file rather than multiple files.
So here in this tutorial, we are gonna learn how to decompress files with .tar as their extension and extract the information from them and also understand the concepts of compressing files into a single file with .tar extension.
So first, let us learn the concepts of data compression!
What is Data Compression?
Data compressing is subject to a space-time complexity trade-off. Several techniques used for reducing the number of bits needed to represent an item of digital data, either to save storage or to use less bandwidth when transmitting the data over a network.
There are two categories of data compression.
- One of the same is used to reduce the size of the single file to save storage space and also to make data transmission faster and lighter. The JPEG image, MPEG video. MP3 audio or the G.7xx voice formats are widely used.
- The second method usually includes Compressing a group of files which is otherwise called file archiving. This method is widely used for storing documents, where the method is not aware about the type of content’s purpose. ZIP, RAR, GIF, TAR come under this category.
- While sending data, lossy compression is not preferred. We must have integrity with the original file when decompressed. It is called lossless compression which we’re gonna discuss over here.
Step 1 Compressing the files using tar Command
For demo we’re gonna create four random test file, th1, th2, th3, th4.
So for sending them over the internet, we need to compress them for speed and reliability. So we are going to combine them into a single archive file by typing
tar -cvf thehackr.tar th1 th2 th3 th4
- tar archiving command
- -c means create
- -v means verbose
- -f to give permission to write or read from or to the following file
- thehackr.tar name of the archive file to be created
Step 2 Display what’s inside the Archive
To list what’s inside the archive, type
tar -tvf thehackr.tar
Step 3 Extracting the data from the Archive
To extract or decompress those files which are archived into a file with .tar as extension, simply type
tar -xvf thehackr.tar
If you do not want the output files to be printed on the shell, simply remove the -v switch from the command.
tar -xf thehackr.tar