Software

Let’s Decompress A File (tar.gz) In The Terminal

Pretty much every Linux user has to look up how to decompress a file in the terminal. Ask them to do it by rote and they’ll balk, but it’s actually pretty easy. Heck, there are entire jokes and comic strips dedicated to it. The thing is, it’s actually pretty easy and this article is going to show you how.

The tool we’ll be using for this is called ‘tar’ and the man page helpfully describes it like this:

tar – an archiving utility

If one is curious, the .gz is for gzip. It’s both a file format and a compression utility. The .tar is a container for multiple files. Its name comes from tape archive, where one would store multiple compressed files in one file. Think of it as a container for .gz files, if that helps.

Today’s article is meant to be REALLY basic, so we’re only going to approach this with the tar command. The only goal of this article is to teach you how to decompress a .tar.gz from the terminal. (There are a dozen GUI ways to do this, but not all systems have a GUI available.)

Decompress A File:

This article requires an open terminal. You can do so with your keyboard – just press CTRL + ALT + T and your default terminal should open.

You’ll also need a .tar.gz, but I’m going to assume you already have. If you don’t have one, you’re bound to reach that eventuality so long as you continue to use Linux. It’s a preferred file distribution format for things like source code. 

Anyhow, it’s really simple. Navigate to the folder where your .tar.gz file exists and run the following command:

tar –xvzf file.tar.gz

You really only need to remember the vzf. In order, those stand for verbose (tells you what’s going on), z (decompress the files inside), and f (means the name of the file you’re working on).

The x flag means extract and we’ll get back to that in a moment.

You can even tell tar to extract the files in a specific directory. That’d look like this:

tar –xvzf file.tar.gz -C /path/to/extract

But, that’s not too terribly important, so long as you clean up after yourself and don’t leave a bunch of clutter. 

Let’s get back to that x flag. See, if you want to go the other way, that is to compress some files, you just change the x to a c.

In this case, we’re only to cover compressing all the files in a specific folder. That’s a little something like this:

tar –cvzf documents.tar.gz /directory/to/compress

So, really, you only need to remember the “vzf” and x for extract or c for compress. That’s the basics of decompressing a file in the terminal. There are a zillion possible combinations and the man page for tar is about a mile long.

In the vast majority of cases, those are the only two ways you’re going to use the command. If you need something more specific, check man tar.

Closure:

And, there you have it. You have the very basics on how to decompress a file from the terminal. There’s a lot more to the tarball but we really don’t need to cover that. If you need more, there’s the manual – but you probably won’t need more than that.

Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your own site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

KGIII

Retired mathematician, residing in the mountains of Maine. I may be old and wise, but I am not infallible. Please point out any errors. And, as always, thanks again for reading.

Recent Posts

Enable/Disable Your Network Interface

Today we'll cover one way to enable or disable your network interface in the Linux…

6 months ago

Check Your NIC Speed In The Terminal

Today's exercise is a nice and simple exercise where we check your NIC speed in…

6 months ago

Easily Monitor Your Wireless Connection

Have you ever wanted to easily monitor your wireless connection? Well, now you can learn…

6 months ago

Count The Files In A Directory

I think I've covered this before with the ls command but this time we'll count…

6 months ago

Get System Information With The ‘uname’ Command In Linux

Today we'll be learning about a basic Linux command that's known as 'uname' and it…

6 months ago

hardinfo Has Been Rebooted As hardinfo2

If you've used hardinfo in the past, it may interest you to know that hardinfo…

6 months ago