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 7 '16 at 22:28
  • Probably waiting for a tape in /dev/rmt0... – Jeff Schaller Mar 7 '16 at 22:29

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 modern implementations like GNU tar however, instead of the first tape device, it reads the archive from stdin.

If tar's stdin is a terminal, 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 tar xf - < file for portability
xzcat file.xz | tar x
  • 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 7 '16 at 22:42
  • Also be aware of the $TAPE environment variable, which provides an alternative source of "default device" – roaima Mar 7 '16 at 22:49
  • 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 7 '16 at 23:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.