My question is similar to the question What does the -f parameter do in the tar command, but it pertains to archive extraction. If I issue tar x
instead of tar xf mytarball.tar
, is it expecting I "enter" the archive through stdin? And this should be terminated by Ctrl-Z?
-
It hangs, waiting for input. – Tosh Mar 07 '16 at 22:28
-
1Probably waiting for a tape in /dev/rmt0... – Jeff Schaller Mar 07 '16 at 22:29
1 Answers
That depends on the tar
implementation. tar
being the tape archiver, with most tar
implementations, if you don't give a f
option, with x
, tar
will extract data from some tape device.
In some tar
implementations including GNU's, libarchive's and star
however, instead of the first tape device, it reads the archive from stdin.
In those same implementations, the path of the tape device can also be specified with the $TAPE
environment variable when the f
option is not provided.
If tar
's stdin is a terminal device, like when you run tar x
at a shell prompt in a terminal without input redirection, then yes, you'd have to type the content of the archive at the keyboard (which is going to be very tricky to do considering that tar archives are binary format) and finish by pressing the key or key-combination that sends the eof
character twice (generally ^D
(0x4) which is generally obtained by pressing Ctrl+D).
Generally, you don't type the content of the archive, but would rather set stdin to a file or a pipe or socket like
tar x < file # better as tar xf - < file for portability
xzcat file.xz | tar x

- 544,893
-
Thank you Stéphane Chazelas for the detailed answer. Could you explain what "# better" is in the syntax? As I running this as a superuser or root? – Tosh Mar 07 '16 at 22:42
-
Could you explain why you believe that gtar is a modern tar implementation? IIRC, star used stdin/stdout as default at least 15 years before gtar started to do the same. – schily Mar 07 '16 at 23:39