How to uncompress directly from terminal if I have the URL of the file?
For example :
unzip destination-folder-on-my-pc 2 Answers
If unzip would have adhered to the pipes and filters architectural style characteristic of Unix, then one would expect to be able to do this by piping the output of wget into the input of unzip:
wget -O - | (cd destination-folder && unzip -)Where the the dash after -O means standard output, the dash after unzip means standard input and the parenthesised right hand side starts a subshell in the correct directory.
However the ZIP format stores its contents index at the end of the file, and unzip needs to read this before it can start decompressing. So, contrary to gzip et al, it cannot decompress a stream in one pass.
As a workaround you need a temporary file:
wget -O /tmp/z.$$ && (cd destination-folder && unzip /tmp/z.$$)Where the $$ are just used to generate a non-colliding number.
Instead of running the subshell, you could use the -d option of unzip. And for added hygiene, clean up your temporary file:
wget -O /tmp/z.$$ && unzip -d destination-folder /tmp/z.$$ && rm /tmp/z.$$ 6 You need more than one step:
Go into your destination folder
cd destinationDownload the file
wgetExtract the file
unzip test.zip
To use only one command use a script:
#!/bin/bash
wget -P "/tmp" "$1"
filename=$(awk -F'/' {print $NF})
unzip "$filename" -d "$2"
rm "/tmp/$filename"Open an editor to create a new file called
unzip_by_urland put it either in~/binor/usr/bin/localnano unzip_by_urlAnd paste the code above.
Save and close and
Make the file executable
chmod +x /path/to/file/unzip_by_urlNow start the script with:
unzip_by_url