Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am pretty sure I am not the only one with the following problem: every time I need to uncompress a file in *nix I can't remember all the switches, and end up googling it, which is surprizing considering how often I need to do this.

Do you have a good compression cheat sheet? Or how about a mnemonic for all those nasty switches in tar?

I am making this article a wiki so that we can create a nice cheat sheet here.

Oh, and about man pages: is there's one thing they are not helpful for, it's for figuring out how to uncompress a file.

share|improve this question

migrated from Jun 24 '10 at 13:11

This question came from our site for professional and enthusiast programmers.

use the manual pages, then you don't have to create a wiki, and only have to remember the man command :-) man(1) – Florenz Kley Mar 25 '11 at 14:09
eXtract Zee File is how I remember it – Canadian Luke Aug 5 '13 at 20:20
Create Zee Vocking File might be appropriate for creating a .tar.gz – CousinCocaine Oct 14 '13 at 9:00

15 Answers 15

up vote 57 down vote accepted

Or how about using the shell with advanced completion capabilities (like zsh or fresh versions of bash) which will complete the options for you, with comprehensive help? :))

Regarding tar: just look at the "qwerty" keyboard. There are letters "zxcvf" next to each other. You need either "tar czvf file.tar.gz files" or "tar xzvf file.tar.gz".

share|improve this answer
Props for actually answering the question :) – Rich Oct 21 '08 at 22:28
Now, that is a COOL "qwerty" tip! :) – ramayac Oct 22 '08 at 3:04
fricking awesome! – deadprogrammer Oct 22 '08 at 13:14
Another tip is that the z option (or the j option for .bz2 files) is not needed when extracting with modern versions of tar. It automatically uncompresses the file. – Nate Aug 8 '09 at 14:38
I've used tar about ten billion times and never noticed that all the most commonly used options are right next to each other on the keyboard. headsmack – Tyler McHenry Aug 8 '09 at 14:52

Tar option summary

Y'all are welcome to edit this to add more esoteric switches but here are the basics:

  • x - extract files
  • c - create archive
  • t - list files
  • v - verbose (list files as it processes them)
  • j - use bz2 compression
  • z - use gz compression
  • f - read or write files to disk


Uncompress a tar.gz file: tar zxf tarball.tar.gz

Uncompress a tar.bz2 file: tar jxf tarball.tar.bz2

Create a tar.gz file: tar zcvf tarvall.tar.gz mydir/*

share|improve this answer

There's a small Perl script called "unp".

unp filename.tar.gz

...and it extracts everything. Works with any compressed file as long as you have the right binaries. And you just forget about syntax or any of that crap. Check your Linux distribution's repositories. It should be there (at least on Arch, Debian and Ubuntu).

share|improve this answer
Cool, that is new to me. Thanks for the tip! – ramayac Oct 21 '08 at 22:33
Even after using tar for quite a long time I still need to google for the stupid flags. unp is the way to go. – Yada May 23 '15 at 9:23

Just type tar --help and there's your cheatsheet.

share|improve this answer
seriously, have you ever tried reading that man page? – deadprogrammer Oct 21 '08 at 22:05
It might be a bit unreadable and long but I think it works well for just looking up the name of an option. You can also grep for the option you're looking for, i.e. 'tar --help | grep extract'. – Jeremy Ruten Oct 21 '08 at 22:16
Great. And then you have to wade through a man-page that (among the stuff you are looking for) tells you tons of archaic streamer commands and options noone except the developer needs. – Nils Pipenbrinck Oct 21 '08 at 23:42
I really don't see what's so hard about it. To extract an archive, just find the extract option and add -x to your command. If you want it verbose, find that option and add a v to get -xv. Then continue until you get the exact command you want. It even has example commands for common operations. – Jeremy Ruten Oct 22 '08 at 18:59
Jeremy, the real problem is you may not always know the proper vocabulary. As such, it's easy to get confused and find similar options and have them not work. Then, you have to place (some) of them in proper order. This is non-trivial for someone migrating away from Windows. Even more-so if they didn't know scripting in Windows. – Nazadus Aug 8 '09 at 15:03

Really with a frequent usage I make difference between extracting (x) data and compressing (c) data:

To extract:

tar xzf data.tgz

To compress:

tar czf data.tgz

Furthermore you can add two functions too your .bashrc :

function extract () {     
        if ($# -ne 1); then
                echo "Usage: $0  `<compressed archive>"`
                exit 1
        tar xzf $1

function compress () {
        if ($# -ne 2); then
                echo "Usage: $0 `<compressed archive> <files|directories>"`
                exit 1
        tar czf $1 $2

There is another nice extract function, it detect the extension of your compressed file and do the job for you:

extract () {
   if [ -f $1 ] ; then
       case $1 in
           *.tar.bz2)   tar xvjf $1    ;;
           *.tar.gz)    tar xvzf $1    ;;
           *.bz2)       bunzip2 $1     ;;
           *.rar)       unrar x $1       ;;
           *.gz)        gunzip $1      ;;
           *.tar)       tar xvf $1     ;;
           *.tbz2)      tar xvjf $1    ;;
           *.tgz)       tar xvzf $1    ;;
           *.zip)       unzip $1       ;;
           *.Z)         uncompress $1  ;;
           *.7z)        7z x $1        ;;
           *)           echo "don't know how to extract '$1'..." ;;
       echo "'$1' is not a valid file!"
share|improve this answer

If you have trouble remembering the tar options, try using pipes:

  • zcat file.tar.gz | tar xvf -
  • bzcat file.tar.bz2 | tar xvf -

Replace tar xv with tar tv to just view the tarball's contents.

Personally, I use the following mnemonics:

  • t, x, or c for "tabulating", "xtracting", or "creating", respectively.
  • v for listing all the files.
  • z, j, or nothing for tar.gz, tar.bz2, or plain .tar, respectively.
  • f for giving a filename, vs. the default of using stdin/stdout or a tape device.

Although "j" and "bzip2" seem to have nothing to do with each other, I find it easy to remember this exception.

Also, I find it funny that Googling has replaced "man tar".

share|improve this answer
You should get in the habit of always providing the f option: it's only recently that distributions of tar default to f -, the historical default is f /dev/rmt0 or similar. After all, tar is the Tape ARchiver. – ephemient Oct 21 '08 at 23:25
whats tabulating? – Claudiu Aug 8 '09 at 15:59

I do the following

To create a tar: tar czvf foo.tar.gz

To untar tar zxvf foo.tar.gz

These should be the primary switches you need to worry about.

c - create z - compress/uncompress x - extracte v - verbose f - file

You can do some fancier stuff like tar and untar inline while you are trying to move files across directories like so

tar cf - | (cd ; tar xvf - )


share|improve this answer

Man is your friend.

man tar

share|improve this answer

90% of the time I just use

tar -xvf file.*

x: extract
v: be verbose (optional)
f: input file (tar, gz, bzip2, etc...)

Easy, huh? :)
Use Fileroller, or Ark if your not in a console.

share|improve this answer
Until now, I've been using fileroller, but currently I'm out of luck because the version I have uses 1.1 Gb of memory. – Andrew Grimm Jul 14 '09 at 0:37

I've been using a Perl script called aunpack, part of the atool project, for many years now. So you just run: aunpack foo.{zip/tar.gz/tar.bz2} and it does the correct thing based on the file extension.

The other benefit of aunpack is that it won't pollute the current directory with lots of files. Say there are 20 files in that are not in a subdirectory. Instead of spewing these files in the current directory, aunpack will create a foo subdirectory and put all files in there.

share|improve this answer

The Three Most Frequently Used Operations:

--create -c

Create a new tar archive.

--list -t

List the contents of an archive.

--extract -x

Extract one or more members from an archive.

The Five Advanced tar Operations:

--append -r

Add new entries to an archive that already exists.

--update -u

Add more recent copies of archive members to the end of an archive, if they exist.

--concatenate --catenate -A

Add one or more pre-existing archives to the end of another archive.


Delete items from an archive (does not work on tapes).

--compare --diff -d

Compare archive members to their counterparts in the file system.

share|improve this answer

I always read out the commands in my mind, while typing

compress verbose zip-file

tar cvzf FILE

extract verbose zip file FILE

tar xvzf FILE
share|improve this answer

I do not remember :). I just use "tar xf file" to compress, and use FileRoller to create packages.

share|improve this answer
tar xf extracts, and neither compresses nor decompresses... so it's probably best you stick to FileRoller! – Rich Oct 21 '08 at 22:29
tar xf on a compressed file (file.tar.bz2 for example) extracts and decompress it... – Kknd Oct 22 '08 at 21:30

I think it´s easy to think of what you want and not just some letters.

To illustrate, I will use an example of how to extract file.tar.gz:

Since it´s a tar file, you should use the the tar program. Then it´s the options:

  1. x since you want to e**x**tract.
  2. z if the file ends with .gz. (gz is after tar in the file name) This option gunzip the archive.
  3. f for file followed by the archive name.

This is demonstrated in the example below:

tar xzf file.tar.gz
share|improve this answer

The way I remember is that it's always "tar XXvf ", where the two Xs are

  • x for e**X**tract or c for Create and,
  • either z = gzip, j = bzip2 (gzip is more common so it's usually z, for whatever reason the j = bzip2 is just stuck in my head).

Occasionally you run into compressed but not tarred files where you add un to whatever the compression type is. e.g. g**un**zip or b**un**zip2.

If anything, I forget the 2 and sometimes type "bzip".

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .