TAR is a very powerful Linux command that is generally used for compressing the multiple files into a single TAR file. However, apart from that, it can also be used for printing the contents of a TAR file, extracting the contents of a TAR file, etc. In this guide, we will discuss the options that can be used with this command as well as a few use-cases in which this command can prove to be extremely helpful.
To take a look at all the options that are available with the TAR command, you can run the following command:
$tar --help
The options available with the TAR command are shown in the following image:
Following are a few examples that will help you out in using the TAR command in an effective manner:
In this example, we compress the multiple text files into a single TAR file. For that, we run the following command:
$ tar –czvf files.tar.gz file1.txt file2.txt file3.txt
This command creates a TAR file named “files.tar.gz” and adds the text files named “file1.txt”, “file2.txt”, and “file3.txt” to this TAR file.
The compression of these files produces the following output on the terminal:
You can also display the contents of a TAR file by running the following command:
$ tar –tf files.tar.gz
The contents of our TAR file are shown in the following image:
In this example, we add a text file to an already existing TAR file. For that, we use the following command:
$ tar –rvf files.tar file4.txt
If the name of the file to be added appears in the output, it means that the specified file has been successfully added to the TAR file as shown in the following image:
In this example, we attempt to remove a file from a TAR file. For that, we use the following command:
$ tar --delete –f files.tar file4.txt
This command removes the file named “file4.txt” from our TAR file as shown in the following image:
This article explained the usage of the TAR command in Linux. After giving you an overview of this command, we shared the command with which you can view all the options available with this command. After that, we shared some examples with you that makes the usage of this command easier for you.
You’ve recently installed VMware Workstation on your Ubuntu system and encountered the frustrating “Could not…
Have you ever found yourself staring at a terminal full of 404 errors while trying…
One particularly frustrating error that many users face when trying to upgrade from Ubuntu 18.04 …
In the world of containerization, time synchronization issues can create unexpected roadblocks when working with…
If you’ve recently upgraded to Ubuntu 23.04 or newer, you might have encountered a frustrating…
Canonical announces the General Availability of Ubuntu for the NVIDIA® Jetson Orin™ for edge AI…