These tar files work like a portable container to store various files, and it is also known as a tarball. However, many people can’t find out how to open a tar file in Linux, so you also want to learn how to open tar files and then read our article. This article will cover complete information on how to open tar files in Linux without facing errors.
How to Open Tar file Linux
tar Utility
Let’s consider that we want to extract and open a doc file, and then we can use the below command to unzip the file on Linux:
Remember that the tar.gz file is a combination of the .gz and .tar files, so it is an archive file with other files.
As you can see in the above command, we have used xvzf because these have specific meaning and instructions for the system, and they are:
- x: This command instructs to extract the files from a particular zip file.
- v: This command stands for verbose that works to list out the files
- Z: This command instructs to decompress the files.
- F: This command instructs the filename on which you want to work.
In case you want to create the tar.gz file, then use the following command:
The doc file is available in the document directory, so we have used Documents at the last of the commands.
In case you want to add various files to the tar file, then execute the following command:
In the above command, we have used cvf, so “c” where c is used to creates a new archive.
Finally, use the below command to extract a tar file in Linux:
gzip Utility
First, we will describe the procedure to extract or compress the Tar file on Linux:
Open the Linux terminal and execute the following command to compress the file as tar:
In the above command, we are compressing the xyz.txt file as a tar.gz file. After squeezing the file, use the ls to confirm that the file is compressed successfully.
For extracting the xyz.txt file, you can execute the following command:
Finally, execute the ls command to confirm the file’s extension.
In case you want to compress all of the .txt files in a specific directory, then you can type:
In the above command, “*” is a wildcard for ” number of any characters.” Remember, this command can work on filenames with a specific extension .txt. You can use this way for all file types that include .jpg, .doc, and gzip.txt.
Conclusion
This is how you can easily extract and open tar files in Linux without any errors. As we have mentioned earlier, tar files store the files in a compressed manner, so you have to extract these files for using them. The above procedures are tried and tested on multiple Linux machines, but you have to follow all of these steps carefully.