In most versions of tar
, there are two different modes, depending on whether you put a minus before your options.
The top of the AIX tar man page summarizes the differences:
Berkeley Standards:
tar {c|r|t|u|x} ... [ Archive ] Directory | File ...
X/Open Standards:
tar {-c|-r|-t|-u|-x} ... [-f Archive] ... [-C Directory] File | Directory...
Without the minus, tar
works in Berkeley compatibility mode. In this mode, the options don't follow now-standard UNIX command line conventions. Instead, all the flags must be placed together (in any order). The f
flag means that the first word after the flags is a file name that should be used instead of the tape drive, /dev/rmt0
. (The t
in tar
stands for tape, and the defaults reflect this.) Also note that there is no -C
option in compatibility mode.
With the minus, tar
works like most UNIX commands. All the flags (and their arguments) must be specified first, then the non-flags come after. -f
takes a file name as an argument (essentially, the file name belongs to the -f
flag), so the file.tar
must come immediately after the -f
. That's why the man page says [-f Archive]
with Archive
next to the -f
. But -x
takes no arguments (filename
does not belong to the -x
). Again, looking at the man page, filename
in your example corresponds to File | Directory...
, which are all the way at the end of the command line.
The fixed versions of your commands look like
(cd /home/dir; tar xvf /path/to/file.tar filename)
and
tar -x -f file.tar -C /home/dir filename
GNU tar does something similar. The Three Option Styles does a good job of explaining the differences.
tar
are you using (tar --version
)?tar --version
but it only display the usage