When I have a tar archive of any format, I can use:

tar xf archive.tar.xz
tar xf anotherarchive.tar.gz

as tar discovers the relevant format by itself.

Now I want to download the archives and extract them without them being saved on the file system using wget:

wget -qO- http://someserver.org/sometar.tar.xz | tar xf -C ~/extractTarget
tar: -C: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now

I realized that the f flag was causing trouble as it expects the actual file. Omitting it, now lets tar complain for the relevant flag.

In case of the gz:

tar: Archive is compressed. Use -z option

and in case of the xz:

tar: Archive is compressed. Use -J option

Adding them makes my command work. Yet since tar is recognizing the archive format, I wonder:

Is there a way for it to extract them without adding the flag just like xf?

1 Answer 1


Use tar xf -. The - is a placeholder for standard input.

  • I still get: tar: Archive is compressed. Use -J option tar: Error is not recoverable: exiting now when running wget -qO- http://downloads.xiph.org/releases/ogg/libogg-1.3.2.tar.xz | tar xf -
    – k0pernikus
    Commented Mar 8, 2015 at 13:50
  • If the data is compressed you would of course have to add the respective uncompress-flags in your tar call (like tar xzf -). If you want some specific decompression that tar does not support you can pipe the output through the decompression first before forwarding it through another pipe to tar.
    – Janis
    Commented Mar 8, 2015 at 13:56
  • 1
    The point of the question was that tar xf does not need any uncompress flag, and I want to achive the exact same thing when piping an archive in from wget.
    – k0pernikus
    Commented Mar 8, 2015 at 13:59
  • @k0pernikus actually, tar does need to be passed uncompress flags, and indeed the specific uncompress flag that is needed. I suppose it could infer it from the extension in theory, but that is not done in practice. So I don't know what you mean. Commented Mar 8, 2015 at 14:01
  • 2
    One more information: I read the tar command has a -a option which automatically detects the compression from the file suffix. If this is enabled in tar by default it would explain why it cannot detect the compression, since there's no file suffix if data is read from pipe.
    – Janis
    Commented Mar 8, 2015 at 14:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .