Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have learned to use tar without '-' for options, like tar cvfz dir.tar.gz Directory/ but I recently came accross the slightly different tar -czvf syntax (I think the 'f' must be the last option in this case).

Both work on linux and Mac OS. Is there a recommended syntax, with ou without '-' which is more portable accross unix flavors ?

share|improve this question
    
See also: unix.stackexchange.com/questions/13573/… –  unor Apr 8 '13 at 10:02

2 Answers 2

up vote 18 down vote accepted

tar is one of those ancient commands from the days when option syntax hadn't been standardized. Because all useful invocations of tar require specifying an operation before providing any file name, most tar implementations interpret their first argument as an option even if it doesn't begin with a -. Most current implementations accept a -; the only exception that I'm aware of is Minix.

Older versions of POSIX and Single Unix included a tar command with no - before the operation specifier. Single Unix v2 had both traditional archivers cpio and tar, but very few flags could be standardized because existing implementations were too different, so the standards introduced a new command, pax, which is the only standard archiver in since Single Unix v3. If you want standard compliance, use pax, but beware that many Linux distributions don't include it in their base installation, and there's no pax in Minix. If you want portability in practice, use tar cf filename.tar.

share|improve this answer

I may be a dinosaur, but I think that habitually using "cvf" instead of "-cvf" is probably more portable. I imagine most Linux distros use GNU tar, and I would guess that the *BSDs do also, but you'll find proprietary Unixes that still use the old SysV tar, which used to require you to not use a '-' in the options.

I do not use "-cvf" (or "-xf" or whatever) and I have no trouble even with bleeding edge Arch linux.

And just as a side note, I think you can use the Sun-standard "jar" command options with or without a '-' as well.

share|improve this answer
    
I agree with your answer, even if the info page of tar (which is very clear about the three styles of specifying options) tells that old options are kept only for compatibility and there are a bunch of options that have NO old correspondence. –  David Costa Jan 5 '12 at 23:28

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.