Before we go into the situation’s specifics, let’s define Archive files so that no Linux newbies are left out. Archived file is a combination of multiple files with metadata information. By combining multiple files and their information into a single file, you may improve the storage and mobility of your data. The basic purpose of Tar is to combine the data but you can also compress the data using other utilities. These compressed files are referred to as Archive files, and they assist users to reduce file size and simplify data management. The tar is one of the must-have utilities for managing various files in Linux.
How Tar file works in Linux
To understand the basic working and syntax of a tar utility, you need to type the below-given command in the terminal:
You will see all the details after entering this command in the terminal that we will also discuss in this article. So after looking at the image you can find the basic syntax of a tar file:
Here OPTION represents your operation choice as to how you want to create a tar file. So before going into the details of creating a tar file you should first confirm whether the tar utility is installed in your system or not otherwise you won’t be able to create a tar file. You can verify that by typing.
As you can see that the tar utility is already installed, and its current version is 1.30, but if by any chance this utility is not installed in your system, then you can do that by entering the command:
Some useful options that are used with the tar command are listed below:
|c||To make (create) a new archive file|
|x||To extract the content of the archive file|
|v||To provide you the additional details of the archive file (Verbose)|
|t||To list the files|
|z||To filter .gz file|
How to make a tar file
To give you a basic understanding of creating a tar file, we have created a folder with three text files that you can see in the documents directory, as shown below.
The next step is to make a tar file that is possible by typing.
Or you can also type:
The above commands are used not only to make a tar file but also compress them in the same folder where the files are present, and you can see that these two commands have created a tar file with .bz2 and .gz format. Also, the asterisk sign (*) ensures that the tar file should include all the files in the current directory in a sequence. Later you can verify the newly created compressed tar file by opening a folder as shown below.
How to extract a tar file
So, if you have downloaded a .tar file from the internet or someone else sends you then you can extract its content by typing.
How to view the content of a tar file
If you have a tar file but you only want to see its content and don’t want to extract it then you can do that by typing.
The above command will give you the basic details about the files that are present inside the tar. So if you are interested in getting more details about the tar file then you can do that by typing.
Tar is a powerful Linux application that not only lets you create tar files but can also extract them. Moreover, you can also inspect the contents of various tar archive files without having to extract them. In this tutorial, we have learned how to use different options and commands in the terminal to inspect the contents of tar files and compress the tar files.