Server Fault is a question and answer site for system and network administrators. 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

tar -xvfz foo.tar.gz returns an error tar: z: Cannot open: No such file or directory

This is completely understandable - the f switch expects a filename, and so needs to be last.

However, omitting the hyphen tar xvfz foot.tar.gz works and uncompresses and untars the file.

I've tested this on OS X 10.8 and Ubuntu 12.04.

Any ideas why?

[edited to add]

I always use tar -zxvf foo.tar.gz. However, this question has arisen because of this xkcd, and my surprise when someone insisted that tar xvfz would work.

enter image description here

share|improve this question
So sorry: – Byte56 Feb 1 '13 at 19:22
up vote 56 down vote accepted

tar has 3 types of syntax (according to this ):

  • long options (--file)
  • short options (-f)
  • old options (f)

For the old option syntax, all the letters must follow "tar" and must all fall into a single clump with no spaces. The order of the letters doesn't really matter, so long as the arguments to those letters follow the same order after the clump of options.

This old way of writing tar options can surprise even experienced users. For example, the two commands:

 # tar cfz archive.tar.gz file
 # tar -cfz archive.tar.gz file

are quite different. The first example uses ‘archive.tar.gz’ as the value for option ‘f’ and recognizes the option ‘z’. The second example, however, uses ‘z’ as the value for option ‘f’ — probably not what was intended.

Old options are kept for compatibility with old versions of tar.

The command with a '-' is equivalent to

tar -czf archive.tar.gz file
tar -cf archive.tar.gz -z file
tar cf archive.tar.gz -z file

That's the reason that your example is working without a "-" and not with "-"

share|improve this answer
That pretty much explains things - thanks. – anu Feb 1 '13 at 19:26
wtf​​​​​​​​unix – BlueRaja Feb 2 '13 at 6:40
Thanks .. found useful!! – Somesh Mar 5 '13 at 6:15

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.