18 Tar Command Examples in Linux

Best Affordable Linux and WordPress Services For Your Business
Outsource Your Linux and WordPress Project and Get it Promptly Completed Remotely and Delivered Online.

If You Appreciate What We Do Here On TecMint, You Should Consider:

  1. Stay Connected to: Twitter | Facebook | Google Plus
  2. Subscribe to our email updates: Sign Up Now
  3. Get your own self-hosted blog with a Free Domain at ($3.45/month).
  4. Become a Supporter - Make a contribution via PayPal
  5. Support us by purchasing our premium books in PDF format.
  6. Support us by taking our online Linux courses

We are thankful for your never ending support.

Ravi Saive

I am Ravi Saive, creator of TecMint. A Computer Geek and Linux Guru who loves to share tricks and tips on Internet. Most Of My Servers runs on Open Source Platform called Linux. Follow Me: Twitter, Facebook and Google+

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide

You may also like...

89 Responses

  1. Rohan says:

    Can you also Pplease include tar with --exclude options, which is really helpful if you have to take entire OS backup excluding /usr, /var, etc.

  2. Mohammed Khan says:

    It was really good example demonstration of using the tar command. However, I faced an issue after the creation of tar. I created a tar on a UNIX server and downloaded it into my windows.

    To my shock, after unziping (using 7-zip) the files inside tar (all txt files) where encrypted. How do I control the encryption while creating a tar?

    This is not the case when I use -xf cmd in the UNIX server.

    Why this encryption of data in UNIX while creating tar?

    –need help

    • Ravi Saive says:


      The tar command never encrypt data or files during creation. It just compress the files into one single format i.e. tar.gz or tar.bz2. May I know how you created tar file in Unix server?

      • Mike says:

        Thanks so much for your post and help Mr. Ravi. I am seeing the same problem, so I think I know what he means. I tar’ed a folder structure on Centos, then moved the tar file to Ubuntu, when I untarred it, all the FILES in all the subfolders were themselves individual tarred files (all files .gz extension instead of the original .jpg extension for example).

        It means that for a folder structure with 10,000 files, in many subfolders, all 10,000 files in subfolders are now individual tar files, and I need to untar 10,000 files? No files in any of the subfolders exist in their original form, they have all been tar’ed to individual tar files. It is unbelievable.

        His question, if I am understanding him, is how to control the tar during tarring so it does NOT tar each individual file in each subfolder as an individual tar file? Under what conditions would anyone want this anyway? Hard to believe in 2018 I am having this kind of basic problem.

  3. Vikram says:

    It’s amazing and I like it

  4. talah shaikh says:

    thanks very much for this tar command information document.

  5. Sunil says:

    In this sentence “The tar is most widely used command to create compressed archive files and that can be moved easily from one disk to “anther” disk or machine to machine.”
    anther should be another.

    And thanks a lot for this tutorial.

  6. Rashmi says:

    Thanks for posting the information.

    It would be good if you could address the following in this page.

    1) Missing word – In this article we will going to review – ‘be’ is missing between ‘we’ and ‘going’ words
    2) Missing word – that might be helpful you – ‘for’ is missing between ‘helpful’ and ‘you’ words
    3) Sentence Correction – Let’s discuss the each option we have used in the above command for creating tar archive file.
    Correction: Let’s discuss each option that we have used in the above command for creating a tar archive file.
    4) Not required: The following example of command – ‘of’ is not needed
    5) Missing word: If you want untar in a different – ‘to’ is missing between ‘want’ and ‘untar’
    6) Correction: To list the content of tar archive file – ‘content’ should be ‘contents’ (Replace ‘content’ with ‘contents’ at appropriate location)
    7) Correction: to a existing compressed tar.gz – ‘a’ should be ‘an’
    8) Correction: If we do try will get tbe following error – ‘tbe’ should be ‘the’
    9) Spelling: ‘archvie’ should be ‘archive’
    10) Spelling: ‘patters’ should be ‘patterns’

  7. David Zuccaro says:

    why do you need a – with option cvf and not need it with option cvfz?

  8. Binh Thanh Nguyen says:

    Thanks, nice tips

  9. Ferdinant says:

    Very nice, and now the second most important one is missing, namely: how to create split tar files into blocks of certain size.

    Anyway it helped me on my way.


    • Ravi Saive says:


      Thanks for finding it helpful, and also thanks for telling about that missing topic “how to create split tar files into blocks of certain size“, we will surely write on this topic and publish it by next week, till then stay tuned to TecMint.com

  10. While extracting a particular file from the tarball, just giving a file name doesn’t work. You need to give the path of the file within the tarball.
    For example: I have taken a backup of my home directory called “/home/aziz” and it contains test1 and test2 files.

    $ tar -xvf /tmp/aziz.tar test1 — This command does not work while extracting a particular called test1
    $ tar -xvf /tmp/aziz.tar home/aziz/test1 — This command works while extracting a file called test1
    $ tar –extract –file=/tmp/aziz.tar home/aziz/test1

Leave a Reply to Ravi Saive Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.