I would like to pipe tarballs (.tar.gz files in this case) I download with GNU Wget (wget) through tar -xzf (to decompress them, if this is unclear) but I don't know how. I have tried:

wget -q -O- ${SRC_URI} | tar -xzf > ${DESTDIR}


wget -q -O- ${SRC_URI} | `tar -xzf` > ${DESTDIR}


wget -q -O- ${SRC_URI} | 'tar -xzf' > ${DESTDIR}

not one even came close to doing what I want. I have also tried omitting the output component > ${DESTDIR} and just letting tar to extract the tarball's contents the way it does by default. Each attempt usually either returned an error like:

tar: option requires an argument -- 'f'

before it would download the tarball, or nothing but then I would check for whether the path set by ${DESTDIR} had been created (as I was leaving tar to generate it) and it had not.


As you're extracting a tar.gz file from stdin, you don't need to specify the f option, tar defaults to reading from stdin.

Assuming you want to extract the contents to $DESTDIR, you also need to use GNU tar's -C (change directory) option.

I've also put " quotes around the variables, in case $SRC_URI or $DESTDIR contain any spaces or shell meta-characters - &, *, ? and the like.

Finally, the {} curly braces around the variables aren't strictly necessary here, but I've left them in anyway - they certainly don't cause any harm.

Putting that all together, you get:

wget -q -O- "${SRC_URI}" | tar -xz -C "${DESTDIR}"
  • And you might want to run mkdir "${DESTDIR}" before the command so the -C can effectively change to that directory: mkdir -p "${DESTDIR}" && wget -q -O- "${SRC_URI}" | tar -xz -C "${DESTDIR}" – Camilo Sampedro Oct 4 '18 at 2:24

You need to specify - as the 'file' to extract. The wget command outputs to STDOUT (-O-) and tar needs to use STDIN as input file: tar zxf - to extract.

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.