How to redirect output of wget as input to unzip?How to curl and unzip to a certain directory?curl to stdout...
How to create a list of dictionaries from a dictionary with lists of different lengths
What was the first LISP compiler?
Can a magnet rip protons from a nucleus?
Is there a sentence that begins with “them”?
Why is the the worst case for this function O(n^2)?
Is it appropriate for a professor to require students to sign a non-disclosure agreement before being taught?
How do I politely hint customers to leave my store, without pretending to need leave store myself?
How can I protect myself in case of a human attack like the murders of the hikers Jespersen and Ueland in Morocco?
Why is differential privacy defined over the exponential function?
Can board a plane to Cameroon without a Cameroonian visa?
Matrices upper triangular alignment
SQL Server table with 4,000,000 rows is 40GB
How much power do LED smart bulb wireless control systems consume when the light is turned off?
Is the space of Radon measures a Polish space or at least separable?
Is there a star over my head?
Usage of Offrir and Donner
Does the mana ability restriction of Pithing Needle refer to the cost or the effect of an activated ability?
Using the Fruit soaked in vodka
Which ping implementation is cygwin using?
Where does the expression "triple-A" comes from?
Will replacing a fake visa with a different fake visa cause me problems when applying for a legal study permit?
Starring Samurais - Several Scribbled Short Stories
Job offer without any details but asking me to withdraw other applications - is it normal?
Could the government trigger by-elections to regain a majority?
How to redirect output of wget as input to unzip?
How to curl and unzip to a certain directory?curl to stdout and untar a zip to a specific directoryListing files from nested zip files without extractingHow redirect input while process is running?Output redirect complexitiesHow to redirect output of cowsay to be the input of zwriteRedirecting sed to curl then to fileQueue up commands while one command is being executedHow to filter and redirect outputcron not executing command with variableHow to redirect output to file to STDOUT?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
I have to download a file from this link. The file download is a zip file which I will have to unzip in the current folder.
Normally, I would download it first, then run the unzip command.
$ wget http://www.vim.org/scripts/download_script.php?src_id=11834 -O temp.zip
$ unzip temp.zip
But in this way, I need to execute two commands, wait for the completion of first one to execute the next one, also, I must know the name of the file temp.zip
to give it to unzip
.
Is it possible to redirect output of wget
to unzip
? Something like
$ unzip < `wget http://www.vim.org/scripts/download_script.php?src_id=11834`
But it didn't work.
bash:
wget
: ambiguous redirect
http://www.vim.org/scripts/download_script.php?src_id=11834
-O temp.zip
Also, wget
got executed twice, and downloaded the file twice.
command-line io-redirection
add a comment |
I have to download a file from this link. The file download is a zip file which I will have to unzip in the current folder.
Normally, I would download it first, then run the unzip command.
$ wget http://www.vim.org/scripts/download_script.php?src_id=11834 -O temp.zip
$ unzip temp.zip
But in this way, I need to execute two commands, wait for the completion of first one to execute the next one, also, I must know the name of the file temp.zip
to give it to unzip
.
Is it possible to redirect output of wget
to unzip
? Something like
$ unzip < `wget http://www.vim.org/scripts/download_script.php?src_id=11834`
But it didn't work.
bash:
wget
: ambiguous redirect
http://www.vim.org/scripts/download_script.php?src_id=11834
-O temp.zip
Also, wget
got executed twice, and downloaded the file twice.
command-line io-redirection
In the latter example, wget probably was executed twice because the ? is a special character in the shell. Putting the URL in ""s should help.
– p-static
Oct 8 '10 at 0:32
This thread seems to have a solution. Haven't tried it myself though. serverfault.com/questions/26474/…
– user37850
Apr 25 '13 at 13:00
add a comment |
I have to download a file from this link. The file download is a zip file which I will have to unzip in the current folder.
Normally, I would download it first, then run the unzip command.
$ wget http://www.vim.org/scripts/download_script.php?src_id=11834 -O temp.zip
$ unzip temp.zip
But in this way, I need to execute two commands, wait for the completion of first one to execute the next one, also, I must know the name of the file temp.zip
to give it to unzip
.
Is it possible to redirect output of wget
to unzip
? Something like
$ unzip < `wget http://www.vim.org/scripts/download_script.php?src_id=11834`
But it didn't work.
bash:
wget
: ambiguous redirect
http://www.vim.org/scripts/download_script.php?src_id=11834
-O temp.zip
Also, wget
got executed twice, and downloaded the file twice.
command-line io-redirection
I have to download a file from this link. The file download is a zip file which I will have to unzip in the current folder.
Normally, I would download it first, then run the unzip command.
$ wget http://www.vim.org/scripts/download_script.php?src_id=11834 -O temp.zip
$ unzip temp.zip
But in this way, I need to execute two commands, wait for the completion of first one to execute the next one, also, I must know the name of the file temp.zip
to give it to unzip
.
Is it possible to redirect output of wget
to unzip
? Something like
$ unzip < `wget http://www.vim.org/scripts/download_script.php?src_id=11834`
But it didn't work.
bash:
wget
: ambiguous redirect
http://www.vim.org/scripts/download_script.php?src_id=11834
-O temp.zip
Also, wget
got executed twice, and downloaded the file twice.
command-line io-redirection
command-line io-redirection
edited Jun 18 '18 at 20:31
Seanny123
1074 bronze badges
1074 bronze badges
asked Oct 4 '10 at 9:10
Andrew-DufresneAndrew-Dufresne
2,0186 gold badges20 silver badges18 bronze badges
2,0186 gold badges20 silver badges18 bronze badges
In the latter example, wget probably was executed twice because the ? is a special character in the shell. Putting the URL in ""s should help.
– p-static
Oct 8 '10 at 0:32
This thread seems to have a solution. Haven't tried it myself though. serverfault.com/questions/26474/…
– user37850
Apr 25 '13 at 13:00
add a comment |
In the latter example, wget probably was executed twice because the ? is a special character in the shell. Putting the URL in ""s should help.
– p-static
Oct 8 '10 at 0:32
This thread seems to have a solution. Haven't tried it myself though. serverfault.com/questions/26474/…
– user37850
Apr 25 '13 at 13:00
In the latter example, wget probably was executed twice because the ? is a special character in the shell. Putting the URL in ""s should help.
– p-static
Oct 8 '10 at 0:32
In the latter example, wget probably was executed twice because the ? is a special character in the shell. Putting the URL in ""s should help.
– p-static
Oct 8 '10 at 0:32
This thread seems to have a solution. Haven't tried it myself though. serverfault.com/questions/26474/…
– user37850
Apr 25 '13 at 13:00
This thread seems to have a solution. Haven't tried it myself though. serverfault.com/questions/26474/…
– user37850
Apr 25 '13 at 13:00
add a comment |
7 Answers
7
active
oldest
votes
You have to download your files to a temp file, because (quoting the unzip man page):
Archives read from standard input
are not yet supported, except with
funzip (and then only the first
member of the archive can be
extracted).
Just bring the commands together:
wget http://www.vim.org/scripts/download_script.php?src_id=11834 -O temp.zip; unzip temp.zip; rm temp.zip
But in order to make it more flexible you should probably put it into a script so you save some typing and in order to make sure you don't accidentally overwrite something you could use the mktemp
command to create a safe filename for your temp file:
#!/bin/bash
TMPFILE=`mktemp`
PWD=`pwd`
wget "$1" -O $TMPFILE
unzip -d $PWD $TMPFILE
rm $TMPFILE
Iswget file.zip && unzip file.zip
the same aswget file.zip; unzip file.zip
or is one preferred over the other? Thanks :)
– jaggedsoft
Dec 3 '16 at 20:10
7
@NextLocalwget && unzip
will run unzip only if wget succeeded.wget ; unzip
will run unzip anyway, possibly pointing to non existent file.
– temoto
Feb 7 '17 at 11:37
funzip was the answer I was looking for. Terraform (for some reason) packages it's binary as a single file in a zip archive so this was perfect for me.
– Asfand Qazi
Nov 7 '18 at 22:52
add a comment |
This is a repost of my answer to a similar question:
The ZIP file format includes a directory (index) at the end of the archive. This directory says where, within the archive each file is located and thus allows for quick, random access, without reading the entire archive.
This would appear to pose a problem when attempting to read a ZIP archive through a pipe, in that the index is not accessed until the very end and so individual members cannot be correctly extracted until after the file has been entirely read and is no longer available. As such it appears unsurprising that most ZIP decompressors simply fail when the archive is supplied through a pipe.
The directory at the end of the archive is not the only location where file meta information is stored in the archive. In addition, individual entries also include this information in a local file header, for redundancy purposes.
Although not every ZIP decompressor will use local file headers when the index is unavailable, the tar and cpio front ends to libarchive (a.k.a. bsdtar and bsdcpio) can and will do so when reading through a pipe, meaning that the following is possible:
wget -qO- http://example.org/file.zip | bsdtar -xvf-
1
This is excellent! I would note that tar gives me some warnings about the uncompressed data being the wrong size (expected 0), but the files themselves appear to be undamaged. Guessing this is due to the lack of the index.
– Wyatt8740
Mar 17 '18 at 7:50
1
I have a.zip
-file here that contains files with executable permissions. When I download and pipe intobsdtar
, the exec bits get thrown away. When I download to disk and extract withbsdtar
orunzip
then, the exec bits are honoured.
– Golar Ramblar
May 4 '18 at 16:02
// , @GolarRamblar, didst ever find out why?
– Nathan Basanese
Sep 27 '18 at 19:16
1
@NathanBasanese: here is the answer. In short: A ZIP archive has two places where it stores such information, that can be inconsistent, and depending if the filebsdtar
opens is seekable or not it uses the one or the other place.
– Golar Ramblar
Dec 11 '18 at 15:54
add a comment |
If you have the JDK installed, you can use jar
:
wget -qO- http://example.org/file.zip | jar xvf /dev/stdin
3
I just found thatjar
doesn't preserve file permissions. Nice trick otherwise.
– phunehehe
Dec 25 '16 at 10:15
7
You don't need to give a file param, just use| jar xv
– cricket_007
Aug 25 '17 at 15:55
add a comment |
I don't think you even want to bother piping wget's output into unzip.
From the wikipedia "ZIP (file format)" article:
A ZIP file is identified by the presence of a central directory located at the end of the file.
wget has to completely finish the download before unzip can do any work, so they run sequentially, not interwoven as one might think.
add a comment |
The proper syntax would be:
$ unzip <(curl -sL https://www.winpcap.org/archive/1.0-docs.zip)
but it won't work, because of the error (Info-ZIP on Debian):
lseek(3, 0, SEEK_SET) = -1 ESPIPE (Illegal seek)
Archive: /dev/fd/63
End-of-central-directory signature not found. Either this file is not
a zipfile, or it constitutes one disk of a multi-part archive. In the
latter case the central directory and zipfile comment will be found on
the last disk(s) of this archive.
unzip: cannot find zipfile directory in one of /dev/fd/63 or
/dev/fd/63.zip, and cannot find /dev/fd/63.ZIP, period.
or on BSD/OS X:
Trying to read large file (> 2 GiB) without large file support
This is, because the standard zip tools are mainly using lseek
function in order to set the file offset at the end to read its end of central directory record. It is located at the end of the archive structure and it is required to read the list of the files (see: Zip file format structure). Therefore the file cannot be FIFO, pipe, terminal device or any other dynamic, because the input object cannot be positioned by the lseek
function.
So you have the following workarounds:
- use different kind of compression (e.g.
tar.gz
), - you have to use two separate commands,
- use alternative tools (as suggested in other answers),
- create an alias or function to use multiple commands.
I think it still could be a FIFO. You'd just have to keep reading from the FIFO until EOF (effectively buffering the whole FIFO in memory or in a temp file). Totally doable to ease script creation, but not very useful.
– Evan Carroll
Oct 9 '16 at 20:28
add a comment |
Repost of my answer:
BusyBox's unzip
can take stdin and extract all the files.
wget -qO- http://downloads.wordpress.org/plugin/akismet.2.5.3.zip | busybox unzip -
The dash after unzip
is to use stdin as input.
You can even,
cat file.zip | busybox unzip -
But that's just redundant of unzip file.zip
.
If your distro uses BusyBox by default (e.g. Alpine), just run unzip -
.
Very useful trick, thanks !
– Brice
May 30 at 11:39
add a comment |
This works for me quite well:
tar xvf <(curl -sL http://www.vim.org/scripts/download_script.php?src_id=11834)
jar xvf <(curl -sL http://www.vim.org/scripts/download_script.php?src_id=11834)
wget -qO- http://www.vim.org/scripts/download_script.php?src_id=11834 | tar xvf -
wget -qO- http://www.vim.org/scripts/download_script.php?src_id=11834 | jar xvf -
New contributor
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f2690%2fhow-to-redirect-output-of-wget-as-input-to-unzip%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
7 Answers
7
active
oldest
votes
7 Answers
7
active
oldest
votes
active
oldest
votes
active
oldest
votes
You have to download your files to a temp file, because (quoting the unzip man page):
Archives read from standard input
are not yet supported, except with
funzip (and then only the first
member of the archive can be
extracted).
Just bring the commands together:
wget http://www.vim.org/scripts/download_script.php?src_id=11834 -O temp.zip; unzip temp.zip; rm temp.zip
But in order to make it more flexible you should probably put it into a script so you save some typing and in order to make sure you don't accidentally overwrite something you could use the mktemp
command to create a safe filename for your temp file:
#!/bin/bash
TMPFILE=`mktemp`
PWD=`pwd`
wget "$1" -O $TMPFILE
unzip -d $PWD $TMPFILE
rm $TMPFILE
Iswget file.zip && unzip file.zip
the same aswget file.zip; unzip file.zip
or is one preferred over the other? Thanks :)
– jaggedsoft
Dec 3 '16 at 20:10
7
@NextLocalwget && unzip
will run unzip only if wget succeeded.wget ; unzip
will run unzip anyway, possibly pointing to non existent file.
– temoto
Feb 7 '17 at 11:37
funzip was the answer I was looking for. Terraform (for some reason) packages it's binary as a single file in a zip archive so this was perfect for me.
– Asfand Qazi
Nov 7 '18 at 22:52
add a comment |
You have to download your files to a temp file, because (quoting the unzip man page):
Archives read from standard input
are not yet supported, except with
funzip (and then only the first
member of the archive can be
extracted).
Just bring the commands together:
wget http://www.vim.org/scripts/download_script.php?src_id=11834 -O temp.zip; unzip temp.zip; rm temp.zip
But in order to make it more flexible you should probably put it into a script so you save some typing and in order to make sure you don't accidentally overwrite something you could use the mktemp
command to create a safe filename for your temp file:
#!/bin/bash
TMPFILE=`mktemp`
PWD=`pwd`
wget "$1" -O $TMPFILE
unzip -d $PWD $TMPFILE
rm $TMPFILE
Iswget file.zip && unzip file.zip
the same aswget file.zip; unzip file.zip
or is one preferred over the other? Thanks :)
– jaggedsoft
Dec 3 '16 at 20:10
7
@NextLocalwget && unzip
will run unzip only if wget succeeded.wget ; unzip
will run unzip anyway, possibly pointing to non existent file.
– temoto
Feb 7 '17 at 11:37
funzip was the answer I was looking for. Terraform (for some reason) packages it's binary as a single file in a zip archive so this was perfect for me.
– Asfand Qazi
Nov 7 '18 at 22:52
add a comment |
You have to download your files to a temp file, because (quoting the unzip man page):
Archives read from standard input
are not yet supported, except with
funzip (and then only the first
member of the archive can be
extracted).
Just bring the commands together:
wget http://www.vim.org/scripts/download_script.php?src_id=11834 -O temp.zip; unzip temp.zip; rm temp.zip
But in order to make it more flexible you should probably put it into a script so you save some typing and in order to make sure you don't accidentally overwrite something you could use the mktemp
command to create a safe filename for your temp file:
#!/bin/bash
TMPFILE=`mktemp`
PWD=`pwd`
wget "$1" -O $TMPFILE
unzip -d $PWD $TMPFILE
rm $TMPFILE
You have to download your files to a temp file, because (quoting the unzip man page):
Archives read from standard input
are not yet supported, except with
funzip (and then only the first
member of the archive can be
extracted).
Just bring the commands together:
wget http://www.vim.org/scripts/download_script.php?src_id=11834 -O temp.zip; unzip temp.zip; rm temp.zip
But in order to make it more flexible you should probably put it into a script so you save some typing and in order to make sure you don't accidentally overwrite something you could use the mktemp
command to create a safe filename for your temp file:
#!/bin/bash
TMPFILE=`mktemp`
PWD=`pwd`
wget "$1" -O $TMPFILE
unzip -d $PWD $TMPFILE
rm $TMPFILE
edited Feb 27 '15 at 17:24
Nick
1033 bronze badges
1033 bronze badges
answered Oct 4 '10 at 9:33
tantetante
5,17222 silver badges23 bronze badges
5,17222 silver badges23 bronze badges
Iswget file.zip && unzip file.zip
the same aswget file.zip; unzip file.zip
or is one preferred over the other? Thanks :)
– jaggedsoft
Dec 3 '16 at 20:10
7
@NextLocalwget && unzip
will run unzip only if wget succeeded.wget ; unzip
will run unzip anyway, possibly pointing to non existent file.
– temoto
Feb 7 '17 at 11:37
funzip was the answer I was looking for. Terraform (for some reason) packages it's binary as a single file in a zip archive so this was perfect for me.
– Asfand Qazi
Nov 7 '18 at 22:52
add a comment |
Iswget file.zip && unzip file.zip
the same aswget file.zip; unzip file.zip
or is one preferred over the other? Thanks :)
– jaggedsoft
Dec 3 '16 at 20:10
7
@NextLocalwget && unzip
will run unzip only if wget succeeded.wget ; unzip
will run unzip anyway, possibly pointing to non existent file.
– temoto
Feb 7 '17 at 11:37
funzip was the answer I was looking for. Terraform (for some reason) packages it's binary as a single file in a zip archive so this was perfect for me.
– Asfand Qazi
Nov 7 '18 at 22:52
Is
wget file.zip && unzip file.zip
the same as wget file.zip; unzip file.zip
or is one preferred over the other? Thanks :)– jaggedsoft
Dec 3 '16 at 20:10
Is
wget file.zip && unzip file.zip
the same as wget file.zip; unzip file.zip
or is one preferred over the other? Thanks :)– jaggedsoft
Dec 3 '16 at 20:10
7
7
@NextLocal
wget && unzip
will run unzip only if wget succeeded. wget ; unzip
will run unzip anyway, possibly pointing to non existent file.– temoto
Feb 7 '17 at 11:37
@NextLocal
wget && unzip
will run unzip only if wget succeeded. wget ; unzip
will run unzip anyway, possibly pointing to non existent file.– temoto
Feb 7 '17 at 11:37
funzip was the answer I was looking for. Terraform (for some reason) packages it's binary as a single file in a zip archive so this was perfect for me.
– Asfand Qazi
Nov 7 '18 at 22:52
funzip was the answer I was looking for. Terraform (for some reason) packages it's binary as a single file in a zip archive so this was perfect for me.
– Asfand Qazi
Nov 7 '18 at 22:52
add a comment |
This is a repost of my answer to a similar question:
The ZIP file format includes a directory (index) at the end of the archive. This directory says where, within the archive each file is located and thus allows for quick, random access, without reading the entire archive.
This would appear to pose a problem when attempting to read a ZIP archive through a pipe, in that the index is not accessed until the very end and so individual members cannot be correctly extracted until after the file has been entirely read and is no longer available. As such it appears unsurprising that most ZIP decompressors simply fail when the archive is supplied through a pipe.
The directory at the end of the archive is not the only location where file meta information is stored in the archive. In addition, individual entries also include this information in a local file header, for redundancy purposes.
Although not every ZIP decompressor will use local file headers when the index is unavailable, the tar and cpio front ends to libarchive (a.k.a. bsdtar and bsdcpio) can and will do so when reading through a pipe, meaning that the following is possible:
wget -qO- http://example.org/file.zip | bsdtar -xvf-
1
This is excellent! I would note that tar gives me some warnings about the uncompressed data being the wrong size (expected 0), but the files themselves appear to be undamaged. Guessing this is due to the lack of the index.
– Wyatt8740
Mar 17 '18 at 7:50
1
I have a.zip
-file here that contains files with executable permissions. When I download and pipe intobsdtar
, the exec bits get thrown away. When I download to disk and extract withbsdtar
orunzip
then, the exec bits are honoured.
– Golar Ramblar
May 4 '18 at 16:02
// , @GolarRamblar, didst ever find out why?
– Nathan Basanese
Sep 27 '18 at 19:16
1
@NathanBasanese: here is the answer. In short: A ZIP archive has two places where it stores such information, that can be inconsistent, and depending if the filebsdtar
opens is seekable or not it uses the one or the other place.
– Golar Ramblar
Dec 11 '18 at 15:54
add a comment |
This is a repost of my answer to a similar question:
The ZIP file format includes a directory (index) at the end of the archive. This directory says where, within the archive each file is located and thus allows for quick, random access, without reading the entire archive.
This would appear to pose a problem when attempting to read a ZIP archive through a pipe, in that the index is not accessed until the very end and so individual members cannot be correctly extracted until after the file has been entirely read and is no longer available. As such it appears unsurprising that most ZIP decompressors simply fail when the archive is supplied through a pipe.
The directory at the end of the archive is not the only location where file meta information is stored in the archive. In addition, individual entries also include this information in a local file header, for redundancy purposes.
Although not every ZIP decompressor will use local file headers when the index is unavailable, the tar and cpio front ends to libarchive (a.k.a. bsdtar and bsdcpio) can and will do so when reading through a pipe, meaning that the following is possible:
wget -qO- http://example.org/file.zip | bsdtar -xvf-
1
This is excellent! I would note that tar gives me some warnings about the uncompressed data being the wrong size (expected 0), but the files themselves appear to be undamaged. Guessing this is due to the lack of the index.
– Wyatt8740
Mar 17 '18 at 7:50
1
I have a.zip
-file here that contains files with executable permissions. When I download and pipe intobsdtar
, the exec bits get thrown away. When I download to disk and extract withbsdtar
orunzip
then, the exec bits are honoured.
– Golar Ramblar
May 4 '18 at 16:02
// , @GolarRamblar, didst ever find out why?
– Nathan Basanese
Sep 27 '18 at 19:16
1
@NathanBasanese: here is the answer. In short: A ZIP archive has two places where it stores such information, that can be inconsistent, and depending if the filebsdtar
opens is seekable or not it uses the one or the other place.
– Golar Ramblar
Dec 11 '18 at 15:54
add a comment |
This is a repost of my answer to a similar question:
The ZIP file format includes a directory (index) at the end of the archive. This directory says where, within the archive each file is located and thus allows for quick, random access, without reading the entire archive.
This would appear to pose a problem when attempting to read a ZIP archive through a pipe, in that the index is not accessed until the very end and so individual members cannot be correctly extracted until after the file has been entirely read and is no longer available. As such it appears unsurprising that most ZIP decompressors simply fail when the archive is supplied through a pipe.
The directory at the end of the archive is not the only location where file meta information is stored in the archive. In addition, individual entries also include this information in a local file header, for redundancy purposes.
Although not every ZIP decompressor will use local file headers when the index is unavailable, the tar and cpio front ends to libarchive (a.k.a. bsdtar and bsdcpio) can and will do so when reading through a pipe, meaning that the following is possible:
wget -qO- http://example.org/file.zip | bsdtar -xvf-
This is a repost of my answer to a similar question:
The ZIP file format includes a directory (index) at the end of the archive. This directory says where, within the archive each file is located and thus allows for quick, random access, without reading the entire archive.
This would appear to pose a problem when attempting to read a ZIP archive through a pipe, in that the index is not accessed until the very end and so individual members cannot be correctly extracted until after the file has been entirely read and is no longer available. As such it appears unsurprising that most ZIP decompressors simply fail when the archive is supplied through a pipe.
The directory at the end of the archive is not the only location where file meta information is stored in the archive. In addition, individual entries also include this information in a local file header, for redundancy purposes.
Although not every ZIP decompressor will use local file headers when the index is unavailable, the tar and cpio front ends to libarchive (a.k.a. bsdtar and bsdcpio) can and will do so when reading through a pipe, meaning that the following is possible:
wget -qO- http://example.org/file.zip | bsdtar -xvf-
edited May 23 '17 at 11:33
Community♦
1
1
answered Apr 16 '14 at 18:00
ruarioruario
8516 silver badges2 bronze badges
8516 silver badges2 bronze badges
1
This is excellent! I would note that tar gives me some warnings about the uncompressed data being the wrong size (expected 0), but the files themselves appear to be undamaged. Guessing this is due to the lack of the index.
– Wyatt8740
Mar 17 '18 at 7:50
1
I have a.zip
-file here that contains files with executable permissions. When I download and pipe intobsdtar
, the exec bits get thrown away. When I download to disk and extract withbsdtar
orunzip
then, the exec bits are honoured.
– Golar Ramblar
May 4 '18 at 16:02
// , @GolarRamblar, didst ever find out why?
– Nathan Basanese
Sep 27 '18 at 19:16
1
@NathanBasanese: here is the answer. In short: A ZIP archive has two places where it stores such information, that can be inconsistent, and depending if the filebsdtar
opens is seekable or not it uses the one or the other place.
– Golar Ramblar
Dec 11 '18 at 15:54
add a comment |
1
This is excellent! I would note that tar gives me some warnings about the uncompressed data being the wrong size (expected 0), but the files themselves appear to be undamaged. Guessing this is due to the lack of the index.
– Wyatt8740
Mar 17 '18 at 7:50
1
I have a.zip
-file here that contains files with executable permissions. When I download and pipe intobsdtar
, the exec bits get thrown away. When I download to disk and extract withbsdtar
orunzip
then, the exec bits are honoured.
– Golar Ramblar
May 4 '18 at 16:02
// , @GolarRamblar, didst ever find out why?
– Nathan Basanese
Sep 27 '18 at 19:16
1
@NathanBasanese: here is the answer. In short: A ZIP archive has two places where it stores such information, that can be inconsistent, and depending if the filebsdtar
opens is seekable or not it uses the one or the other place.
– Golar Ramblar
Dec 11 '18 at 15:54
1
1
This is excellent! I would note that tar gives me some warnings about the uncompressed data being the wrong size (expected 0), but the files themselves appear to be undamaged. Guessing this is due to the lack of the index.
– Wyatt8740
Mar 17 '18 at 7:50
This is excellent! I would note that tar gives me some warnings about the uncompressed data being the wrong size (expected 0), but the files themselves appear to be undamaged. Guessing this is due to the lack of the index.
– Wyatt8740
Mar 17 '18 at 7:50
1
1
I have a
.zip
-file here that contains files with executable permissions. When I download and pipe into bsdtar
, the exec bits get thrown away. When I download to disk and extract with bsdtar
or unzip
then, the exec bits are honoured.– Golar Ramblar
May 4 '18 at 16:02
I have a
.zip
-file here that contains files with executable permissions. When I download and pipe into bsdtar
, the exec bits get thrown away. When I download to disk and extract with bsdtar
or unzip
then, the exec bits are honoured.– Golar Ramblar
May 4 '18 at 16:02
// , @GolarRamblar, didst ever find out why?
– Nathan Basanese
Sep 27 '18 at 19:16
// , @GolarRamblar, didst ever find out why?
– Nathan Basanese
Sep 27 '18 at 19:16
1
1
@NathanBasanese: here is the answer. In short: A ZIP archive has two places where it stores such information, that can be inconsistent, and depending if the file
bsdtar
opens is seekable or not it uses the one or the other place.– Golar Ramblar
Dec 11 '18 at 15:54
@NathanBasanese: here is the answer. In short: A ZIP archive has two places where it stores such information, that can be inconsistent, and depending if the file
bsdtar
opens is seekable or not it uses the one or the other place.– Golar Ramblar
Dec 11 '18 at 15:54
add a comment |
If you have the JDK installed, you can use jar
:
wget -qO- http://example.org/file.zip | jar xvf /dev/stdin
3
I just found thatjar
doesn't preserve file permissions. Nice trick otherwise.
– phunehehe
Dec 25 '16 at 10:15
7
You don't need to give a file param, just use| jar xv
– cricket_007
Aug 25 '17 at 15:55
add a comment |
If you have the JDK installed, you can use jar
:
wget -qO- http://example.org/file.zip | jar xvf /dev/stdin
3
I just found thatjar
doesn't preserve file permissions. Nice trick otherwise.
– phunehehe
Dec 25 '16 at 10:15
7
You don't need to give a file param, just use| jar xv
– cricket_007
Aug 25 '17 at 15:55
add a comment |
If you have the JDK installed, you can use jar
:
wget -qO- http://example.org/file.zip | jar xvf /dev/stdin
If you have the JDK installed, you can use jar
:
wget -qO- http://example.org/file.zip | jar xvf /dev/stdin
edited Dec 4 '15 at 17:31
Community♦
1
1
answered Sep 11 '15 at 13:04
Rory HunterRory Hunter
3092 silver badges3 bronze badges
3092 silver badges3 bronze badges
3
I just found thatjar
doesn't preserve file permissions. Nice trick otherwise.
– phunehehe
Dec 25 '16 at 10:15
7
You don't need to give a file param, just use| jar xv
– cricket_007
Aug 25 '17 at 15:55
add a comment |
3
I just found thatjar
doesn't preserve file permissions. Nice trick otherwise.
– phunehehe
Dec 25 '16 at 10:15
7
You don't need to give a file param, just use| jar xv
– cricket_007
Aug 25 '17 at 15:55
3
3
I just found that
jar
doesn't preserve file permissions. Nice trick otherwise.– phunehehe
Dec 25 '16 at 10:15
I just found that
jar
doesn't preserve file permissions. Nice trick otherwise.– phunehehe
Dec 25 '16 at 10:15
7
7
You don't need to give a file param, just use
| jar xv
– cricket_007
Aug 25 '17 at 15:55
You don't need to give a file param, just use
| jar xv
– cricket_007
Aug 25 '17 at 15:55
add a comment |
I don't think you even want to bother piping wget's output into unzip.
From the wikipedia "ZIP (file format)" article:
A ZIP file is identified by the presence of a central directory located at the end of the file.
wget has to completely finish the download before unzip can do any work, so they run sequentially, not interwoven as one might think.
add a comment |
I don't think you even want to bother piping wget's output into unzip.
From the wikipedia "ZIP (file format)" article:
A ZIP file is identified by the presence of a central directory located at the end of the file.
wget has to completely finish the download before unzip can do any work, so they run sequentially, not interwoven as one might think.
add a comment |
I don't think you even want to bother piping wget's output into unzip.
From the wikipedia "ZIP (file format)" article:
A ZIP file is identified by the presence of a central directory located at the end of the file.
wget has to completely finish the download before unzip can do any work, so they run sequentially, not interwoven as one might think.
I don't think you even want to bother piping wget's output into unzip.
From the wikipedia "ZIP (file format)" article:
A ZIP file is identified by the presence of a central directory located at the end of the file.
wget has to completely finish the download before unzip can do any work, so they run sequentially, not interwoven as one might think.
answered Oct 4 '10 at 16:09
Bruce EdigerBruce Ediger
37.1k6 gold badges73 silver badges120 bronze badges
37.1k6 gold badges73 silver badges120 bronze badges
add a comment |
add a comment |
The proper syntax would be:
$ unzip <(curl -sL https://www.winpcap.org/archive/1.0-docs.zip)
but it won't work, because of the error (Info-ZIP on Debian):
lseek(3, 0, SEEK_SET) = -1 ESPIPE (Illegal seek)
Archive: /dev/fd/63
End-of-central-directory signature not found. Either this file is not
a zipfile, or it constitutes one disk of a multi-part archive. In the
latter case the central directory and zipfile comment will be found on
the last disk(s) of this archive.
unzip: cannot find zipfile directory in one of /dev/fd/63 or
/dev/fd/63.zip, and cannot find /dev/fd/63.ZIP, period.
or on BSD/OS X:
Trying to read large file (> 2 GiB) without large file support
This is, because the standard zip tools are mainly using lseek
function in order to set the file offset at the end to read its end of central directory record. It is located at the end of the archive structure and it is required to read the list of the files (see: Zip file format structure). Therefore the file cannot be FIFO, pipe, terminal device or any other dynamic, because the input object cannot be positioned by the lseek
function.
So you have the following workarounds:
- use different kind of compression (e.g.
tar.gz
), - you have to use two separate commands,
- use alternative tools (as suggested in other answers),
- create an alias or function to use multiple commands.
I think it still could be a FIFO. You'd just have to keep reading from the FIFO until EOF (effectively buffering the whole FIFO in memory or in a temp file). Totally doable to ease script creation, but not very useful.
– Evan Carroll
Oct 9 '16 at 20:28
add a comment |
The proper syntax would be:
$ unzip <(curl -sL https://www.winpcap.org/archive/1.0-docs.zip)
but it won't work, because of the error (Info-ZIP on Debian):
lseek(3, 0, SEEK_SET) = -1 ESPIPE (Illegal seek)
Archive: /dev/fd/63
End-of-central-directory signature not found. Either this file is not
a zipfile, or it constitutes one disk of a multi-part archive. In the
latter case the central directory and zipfile comment will be found on
the last disk(s) of this archive.
unzip: cannot find zipfile directory in one of /dev/fd/63 or
/dev/fd/63.zip, and cannot find /dev/fd/63.ZIP, period.
or on BSD/OS X:
Trying to read large file (> 2 GiB) without large file support
This is, because the standard zip tools are mainly using lseek
function in order to set the file offset at the end to read its end of central directory record. It is located at the end of the archive structure and it is required to read the list of the files (see: Zip file format structure). Therefore the file cannot be FIFO, pipe, terminal device or any other dynamic, because the input object cannot be positioned by the lseek
function.
So you have the following workarounds:
- use different kind of compression (e.g.
tar.gz
), - you have to use two separate commands,
- use alternative tools (as suggested in other answers),
- create an alias or function to use multiple commands.
I think it still could be a FIFO. You'd just have to keep reading from the FIFO until EOF (effectively buffering the whole FIFO in memory or in a temp file). Totally doable to ease script creation, but not very useful.
– Evan Carroll
Oct 9 '16 at 20:28
add a comment |
The proper syntax would be:
$ unzip <(curl -sL https://www.winpcap.org/archive/1.0-docs.zip)
but it won't work, because of the error (Info-ZIP on Debian):
lseek(3, 0, SEEK_SET) = -1 ESPIPE (Illegal seek)
Archive: /dev/fd/63
End-of-central-directory signature not found. Either this file is not
a zipfile, or it constitutes one disk of a multi-part archive. In the
latter case the central directory and zipfile comment will be found on
the last disk(s) of this archive.
unzip: cannot find zipfile directory in one of /dev/fd/63 or
/dev/fd/63.zip, and cannot find /dev/fd/63.ZIP, period.
or on BSD/OS X:
Trying to read large file (> 2 GiB) without large file support
This is, because the standard zip tools are mainly using lseek
function in order to set the file offset at the end to read its end of central directory record. It is located at the end of the archive structure and it is required to read the list of the files (see: Zip file format structure). Therefore the file cannot be FIFO, pipe, terminal device or any other dynamic, because the input object cannot be positioned by the lseek
function.
So you have the following workarounds:
- use different kind of compression (e.g.
tar.gz
), - you have to use two separate commands,
- use alternative tools (as suggested in other answers),
- create an alias or function to use multiple commands.
The proper syntax would be:
$ unzip <(curl -sL https://www.winpcap.org/archive/1.0-docs.zip)
but it won't work, because of the error (Info-ZIP on Debian):
lseek(3, 0, SEEK_SET) = -1 ESPIPE (Illegal seek)
Archive: /dev/fd/63
End-of-central-directory signature not found. Either this file is not
a zipfile, or it constitutes one disk of a multi-part archive. In the
latter case the central directory and zipfile comment will be found on
the last disk(s) of this archive.
unzip: cannot find zipfile directory in one of /dev/fd/63 or
/dev/fd/63.zip, and cannot find /dev/fd/63.ZIP, period.
or on BSD/OS X:
Trying to read large file (> 2 GiB) without large file support
This is, because the standard zip tools are mainly using lseek
function in order to set the file offset at the end to read its end of central directory record. It is located at the end of the archive structure and it is required to read the list of the files (see: Zip file format structure). Therefore the file cannot be FIFO, pipe, terminal device or any other dynamic, because the input object cannot be positioned by the lseek
function.
So you have the following workarounds:
- use different kind of compression (e.g.
tar.gz
), - you have to use two separate commands,
- use alternative tools (as suggested in other answers),
- create an alias or function to use multiple commands.
answered Jun 15 '16 at 0:48
kenorbkenorb
10.2k4 gold badges83 silver badges124 bronze badges
10.2k4 gold badges83 silver badges124 bronze badges
I think it still could be a FIFO. You'd just have to keep reading from the FIFO until EOF (effectively buffering the whole FIFO in memory or in a temp file). Totally doable to ease script creation, but not very useful.
– Evan Carroll
Oct 9 '16 at 20:28
add a comment |
I think it still could be a FIFO. You'd just have to keep reading from the FIFO until EOF (effectively buffering the whole FIFO in memory or in a temp file). Totally doable to ease script creation, but not very useful.
– Evan Carroll
Oct 9 '16 at 20:28
I think it still could be a FIFO. You'd just have to keep reading from the FIFO until EOF (effectively buffering the whole FIFO in memory or in a temp file). Totally doable to ease script creation, but not very useful.
– Evan Carroll
Oct 9 '16 at 20:28
I think it still could be a FIFO. You'd just have to keep reading from the FIFO until EOF (effectively buffering the whole FIFO in memory or in a temp file). Totally doable to ease script creation, but not very useful.
– Evan Carroll
Oct 9 '16 at 20:28
add a comment |
Repost of my answer:
BusyBox's unzip
can take stdin and extract all the files.
wget -qO- http://downloads.wordpress.org/plugin/akismet.2.5.3.zip | busybox unzip -
The dash after unzip
is to use stdin as input.
You can even,
cat file.zip | busybox unzip -
But that's just redundant of unzip file.zip
.
If your distro uses BusyBox by default (e.g. Alpine), just run unzip -
.
Very useful trick, thanks !
– Brice
May 30 at 11:39
add a comment |
Repost of my answer:
BusyBox's unzip
can take stdin and extract all the files.
wget -qO- http://downloads.wordpress.org/plugin/akismet.2.5.3.zip | busybox unzip -
The dash after unzip
is to use stdin as input.
You can even,
cat file.zip | busybox unzip -
But that's just redundant of unzip file.zip
.
If your distro uses BusyBox by default (e.g. Alpine), just run unzip -
.
Very useful trick, thanks !
– Brice
May 30 at 11:39
add a comment |
Repost of my answer:
BusyBox's unzip
can take stdin and extract all the files.
wget -qO- http://downloads.wordpress.org/plugin/akismet.2.5.3.zip | busybox unzip -
The dash after unzip
is to use stdin as input.
You can even,
cat file.zip | busybox unzip -
But that's just redundant of unzip file.zip
.
If your distro uses BusyBox by default (e.g. Alpine), just run unzip -
.
Repost of my answer:
BusyBox's unzip
can take stdin and extract all the files.
wget -qO- http://downloads.wordpress.org/plugin/akismet.2.5.3.zip | busybox unzip -
The dash after unzip
is to use stdin as input.
You can even,
cat file.zip | busybox unzip -
But that's just redundant of unzip file.zip
.
If your distro uses BusyBox by default (e.g. Alpine), just run unzip -
.
answered Oct 11 '18 at 12:10
SafteverSaftever
811 silver badge2 bronze badges
811 silver badge2 bronze badges
Very useful trick, thanks !
– Brice
May 30 at 11:39
add a comment |
Very useful trick, thanks !
– Brice
May 30 at 11:39
Very useful trick, thanks !
– Brice
May 30 at 11:39
Very useful trick, thanks !
– Brice
May 30 at 11:39
add a comment |
This works for me quite well:
tar xvf <(curl -sL http://www.vim.org/scripts/download_script.php?src_id=11834)
jar xvf <(curl -sL http://www.vim.org/scripts/download_script.php?src_id=11834)
wget -qO- http://www.vim.org/scripts/download_script.php?src_id=11834 | tar xvf -
wget -qO- http://www.vim.org/scripts/download_script.php?src_id=11834 | jar xvf -
New contributor
add a comment |
This works for me quite well:
tar xvf <(curl -sL http://www.vim.org/scripts/download_script.php?src_id=11834)
jar xvf <(curl -sL http://www.vim.org/scripts/download_script.php?src_id=11834)
wget -qO- http://www.vim.org/scripts/download_script.php?src_id=11834 | tar xvf -
wget -qO- http://www.vim.org/scripts/download_script.php?src_id=11834 | jar xvf -
New contributor
add a comment |
This works for me quite well:
tar xvf <(curl -sL http://www.vim.org/scripts/download_script.php?src_id=11834)
jar xvf <(curl -sL http://www.vim.org/scripts/download_script.php?src_id=11834)
wget -qO- http://www.vim.org/scripts/download_script.php?src_id=11834 | tar xvf -
wget -qO- http://www.vim.org/scripts/download_script.php?src_id=11834 | jar xvf -
New contributor
This works for me quite well:
tar xvf <(curl -sL http://www.vim.org/scripts/download_script.php?src_id=11834)
jar xvf <(curl -sL http://www.vim.org/scripts/download_script.php?src_id=11834)
wget -qO- http://www.vim.org/scripts/download_script.php?src_id=11834 | tar xvf -
wget -qO- http://www.vim.org/scripts/download_script.php?src_id=11834 | jar xvf -
New contributor
edited 2 hours ago
New contributor
answered 3 hours ago
Maksim KostrominMaksim Kostromin
992 bronze badges
992 bronze badges
New contributor
New contributor
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f2690%2fhow-to-redirect-output-of-wget-as-input-to-unzip%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
In the latter example, wget probably was executed twice because the ? is a special character in the shell. Putting the URL in ""s should help.
– p-static
Oct 8 '10 at 0:32
This thread seems to have a solution. Haven't tried it myself though. serverfault.com/questions/26474/…
– user37850
Apr 25 '13 at 13:00