The tar command historically has been one of the few commands that doesn't follow the Unix utility syntax guidelines.
The standards page for tar says:
f
Use the first file operand (or the second, if b has already been specified) as the name of the archive instead of the system-dependent default
While the syntax guidelines include this:
Guideline 5:
One or more options without option-arguments, followed by at most one option that takes an option-argument, should be accepted when grouped behind one '-' delimiter.
So while the command you typed, tar -vcfz dvr_rdk_v1.tar.gz dvr_rdk/
, would be fine on older versions of tar, certain versions of tar that are written to strictly follow the utility syntax guidelines will parse this to mean "use z
as the file argument to -f
". So you should use the following to be portable:
tar -cvzf dvr_rdk_v1.tar.gz dvr_rdk/
-
does make a difference, because GNU tar is quirky. Option arguments can't be bundled in the first argument when it doesn't start with a-
, so the argument tof
is the next argument totar
, and sotar vcfz dvr_rdk_v1.tar.gz
is equivalent totar -v -c -f dvr_rdk_v1.tar.gz -z
. – Gilles 'SO- stop being evil' Aug 10 '14 at 22:19z
orj
the archive compression is successful even with-
involved. When I add the hyphen is included it treats the last character in the option as a "file". So as a result I getj
orz
as an archived file if I use this option-cvfz
or-cvfj
. – JohnnyQ Sep 14 '16 at 02:11tar
is my least favorite cli tool. Why is it the way it is? – Josh M. Apr 01 '23 at 01:28