Untar a File in Linux/Ubuntu

Usually a tar file is also compressed using either the gZip or bZip2 compressor. We’ll cover both.

1. If Your File Extension is .tar.gz (or .tgz)

If your tar file is compressed using a gZip compressor, use this command:

The options are pretty straightforward for this:

x: This tells tar to extract the files.

v: This option will list all of the files one by one in the archive. The “v” stands for “verbose.”

z: The z option is very important and tells the tar command to uncompress the file (gzip).

f: This options tells tar that you are going to give it a file name to work with.

2. If Your File Extension is .tar.bz2 (or .tbz)

If your tar file is compressed using a bZip2 compressor, use this command:

This is just about the same as the gzip decompression. The major difference is that the z option has been replaced by the j option.

If you remember, the z option was the uncompress (specifically gzip) flag, so it makes sense that this would be switched out.

j: This will decompress a bzip2 file.

3. Mind-Blowingly-Simple Extraction (The dtrx Function)

There are only a handful of people that actually remember all of the options for the tar command. Luckily, Linux folks are great at making things easier.

Standing for “Do the Right Extraction,” dtrx works as you would hope. The command should be simple for both gZip and bZip2 files:

Installing dtrx

To install dtrx, just use apt-get:

Photo Sources: autogeekonline.net

Ryan Frankel

Questions or Comments? Ask Ryan!

Ask a question and Ryan will respond to you. We strive to provide the best advice on the net and we are here to help you in any way we can.

  • clidre vandijk

    Hello, my file is simply .tar : I’ve tried both 1 and 2, but they don’t work. What can I use to decompress it?

    • penumathsa k c varma

      Hi clidre,
      Plese try the follow command: tar -xvf yourfile.tar

      • praaveen

        @pe@penumathsakcvarma:disqus Thanks lot. Its woking.

  • You can also

    on mac


    How to extract if the extension is tar.xz

    • Sno Himself

      tar xf FILENAME.tar.xz

  • ajmal moochingal

    thanks! 🙂

  • Thank you Ryan…

  • GoldenTreesMC MCPE

    help im on ubuntu 14.04 trying to install secret maryo chronicles and I have the package in my downloads folder. the file is tar.gz, and I tried this, but I cant get secret maryo. and PLEASE don’t say use the “sudo apt-get install smc” command, because I’ve tried like 10 times and it won’t work.
    please tell me a way to add it to the repositories so that will work. PLZ I NEED HELP!!!

  • Joe Schmoe

    can you use the -d AFTER the filename like this
    tar xvjf myDir/compFile.tar.bz2 -d myDir