How to Extract Tar Files to Specific or Different Directory in Linux

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. Use our Linode referral link if you plan to buy VPS (it starts at only $10/month).
  4. Support us via PayPal donate - Make a Donation
  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.

Aaron Kili

Computer Science student at Makerere University. Am a Linux enthusiast and a big fan of FOSS. I have used Linux for one year and six months now. I love to share ideas and knowledge around me and in other places around the world.

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

Receive Your Free Complimentary eBook NOW! -

Download Free Linux eBooks

Linux BASH Programming Cookbook
Getting Started with Ubuntu 16.04
A Newbie's Getting Started Guide to Linux
Introduction to Linux - A Hands on Guide

You may also like...

7 Responses

  1. Jalal Hajigholamali says:

    tar command accepts options without minus[-] sign
    also ‘-j’ option is optional and can be ignore….
    tar xvf …..
    Thanks a lot

  2. Ren says:

    When I extract only specific files from Tar archive, ‘-C’ option is doesn’t work.

    • Ravi Saive says:


      Have you created the separate directory before extracting the specific files to that directory? The -C option is used to specify a different directory and it must exists before extracting files.

      For example,

      # mkdir /tmp/dumpfiles
      # tar -xvf powertop-2.7.tar.gz powertop-2.7/m4/po.m4 -C /tmp/dumpfiles

      Else, you can also extract files withing the current directory without creating a new directory like:

      # tar -xvf powertop-2.7.tar.gz powertop-2.7/m4/lib-ld.m4


  3. David says:

    In the last example, extracting several files from the etc directory out of the tar file, what is the cts/ in the first line of the extracted files?

  4. Konrad says:

    Great post. It would be helpful for Linux beginners to explain the switches used. What does -xf do? You explain the addition of the -v switch which is good. What’s the difference between -C and –directory? In Example 2, you throw in the -z switch and in Example 3, the -j switch without any explanation. Then in example 4, you talk about extracting single files, yet the command also includes an option to extract all files in a specific directory – etc/mysql/. Again, a good example for using different options, but it could use a bit of explanation.

    • Ravi Saive says:


      Yes, we haven’t specified the meaning of each tar command option used in these examples, the reason because we’ve already requested users to read the article that says Mastering tar Command with this 18 Examples in Linux, before heading up further. No issue you can find all these options explanation below:

      c – create a archive file.
      x – extract a archive file.
      v – show the progress of archive file.
      f – filename of archive file.
      t – viewing content of archive file.
      j – filter archive through bzip2.
      z – filter archive through gzip.
      r – append or update files or directories to existing archive file.
      W – Verify a archive file.
      wildcards (*) – Specify patters in unix tar command.

Got something to say? Join the discussion.

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

Join Over 300K+ Linux Users
  1. 177,942
  2. 8,310
  3. 37,548

Are you subscribed?