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.
Here at LinuxAPT, we shall look into the options that can be used with this command as well as a few examples in which this command can prove to be extremely helpful.
TAR Command Options can be seen once you run the below command:
$ tar --help
This command will display all the options available with the TAR command.
Here, we compress the multiple text files into a single TAR file by running 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.
You can also display the contents of a TAR file by running the following command:
$ tar –tf files.tar.gz
The contents of the TAR file will be displayed on the terminal.
Here, we add a text file to an already existing TAR file by running 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.
Here, we will remove a file from a TAR file by running the following command:
$ tar --delete –f files.tar file4.txt
This command removes the file named "file4.txt" from our TAR file.
This article covers the usage of the TAR command in Linux. In fact, the GNU tar (short for Tape ARchiver) command is the most widely used archiving utility in Linux systems. Available directly in the terminal, the tar command helps create, extract, and list archive contents.