Sign up ×
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:… – unor Apr 8 '13 at 10:02

3 Answers 3

up vote 20 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
Also note that if a Linux distro contains pax, it usually comes with the worst known pax implementation (GNU pax) that should be avoided because of many bugs. – schily Sep 9 at 20:28
Also, the ps command has the same behavior, you may omit the - for the options. – perror Sep 9 at 20:37
@perror That's wrong. Many versions of ps don't let you omit the -. The Linux version has options with and without -, but most have different meanings (BSD vs System V compatibility). – Gilles Sep 9 at 20:45
It is true that, most of the time, I only use ps aux... So, I might be (partly) wrong. Sorry. – perror Sep 9 at 20:47

There have been few programs on UNIX that do not follow the current option standard.

One is dd, but dd was derived from the IBM mainframe program DDR (Disk Dump and Restore).

One is ar and the other is tar. From my information, tar wanted to be similar to ar.

All tar implementations work without the - and no useful implementation requires the -. So if you like to write portable scripts, check the SUSv2 standard and only use a commandline that is compatible to SUSv2.

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
You are wrong: tar on AT&T UNIX was written not to have a - but it accepts the - and skips it. The only portable way to call tar is to call it without the - and if you ever find a "tar" implementation that does not accept things without -, this is not tar. – schily Sep 9 at 20:30

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.