Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.
$ ls one.tar.gz
one.tar.gz
$ tar -xvfz one.tar.gz
tar: z: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now
$ tar -xvzf one.tar.gz
one
$ tar -xzvf one.tar.gz
one
$ tar -zxvf one.tar.gz
one
$
share|improve this question

2 Answers 2

up vote 13 down vote accepted

The -f switch takes an argument (the filename). If z appears after the f then it is taken to be the filename.

tar -xvfz one.tar.gz

is the same as

tar -xvf z one.tar.gz

If you had done this:

tar -xvf -z one.tar.gz

then -z would have been taken as the filename and you'd have gotten a similar error.

This, however, would have worked:

tar -xvz -f one.tar.gz

The GNU tar man page states:

The first argument to tar must be one of the options: Acdrtux, followed by any optional functions. The final arguments to tar are the names of the files or directories which should be archived.

Note that unless input is from stdin or output is to stdout (where appropriate), the the -f filename option and argument must be given. While the man page implies that the order is fixed, in reality the options can be in any order. Even this weird one works (but it may not work in all versions of tar):

tar -v files_to_archive* -f xyz.tar.gz -cz

For portability, it's probably better to stick to the idiomatic argument order and even leave off the hyphen:

tar czvf xyz.tar.gz files_to_archive*
share|improve this answer
    
z being last and f taking an argument are not mutually exclusive. –  user31752 Nov 17 '10 at 18:00
    
That's true, but I didn't say that. Perhaps I should have been more explicit and said "immediately after". –  Dennis Williamson Nov 17 '10 at 18:19
    
You didn't say it, but you did begin your sentence with "because", which is an affirmation of his question, which claims z cannot be last, thereby indirectly implying that z cannot be last. Anyway, I am being pedantic. If you remove "because" then your answer is improved IMO. –  user31752 Nov 17 '10 at 18:54
    
Pedantic, yes. I took the question to include an implied "in this sequence". Most of the time with tar you see all the switches concatenated rather than separated as you have in your answer. There's no reason a person couldn't do it the way you show, but the idiom is to do it the way it's shown in the first two successful examples in the question: <operation> <option> <option> <file>. The idiom leads to the inference. –  Dennis Williamson Nov 17 '10 at 19:01

z can be used last:

tar -x -v -f foo.tar.gz  -z

But as stated by @Dennis, the f flag takes an argument.

share|improve this answer

Your Answer

 
discard

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.