Categories: TutorialsUbuntu

TAR Command Options and Examples

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.

Options Used with the TAR Command

To take a look at all the options that are available with the TAR command, you can run the following command:

$

Sponsored
tar --help

The options available with the TAR command are shown in the following image:

Examples of Using the TAR Command

Following are a few examples that will help you out in using the TAR command in an effective manner:

Example 1: Compress Multiple Files into a TAR File

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:

Example 2: View the Contents of a TAR File

You can also display the contents of a TAR file by running the following command:

$ tar –tf files.tar.gz

Sponsored

The contents of our TAR file are shown in the following image:

Example 3: Add Another File to a TAR File

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:

Example 4: Remove a File from a TAR File

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:

Conclusion

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.

 

Ubuntu Server Admin

Recent Posts

Canonical announces 12 year Kubernetes LTS

Canonical’s Kubernetes LTS (Long Term Support) will support FedRAMP compliance and receive at least 12…

16 hours ago

Ubuntu Weekly Newsletter Issue 878

Welcome to the Ubuntu Weekly Newsletter, Issue 878 for the week of February 2 –…

1 day ago

How your feedback shapes the way we support open source software

At Canonical, we firmly believe that delivering an outstanding, customer-centric support experience is impossible without…

2 days ago

How To Install osTicket v1.14 On Ubuntu 20.04

I want to share how to install osTicket v1.14 for Ubuntu 20.04 server. osTicket written…

3 days ago

How To Install WordPress On Ubuntu 20.04

Now I want to share how to install WordPress on ubuntu 20.04 server. WordPress is…

3 days ago

How To Install DNS Server (Bind9) On Ubuntu 20.04

Now I want to share the DNS server installation process on your Ubuntu 20.04 server.…

3 days ago