Velvet Star Monitor

Standout celebrity highlights with iconic style.

updates

Download file extract to specific directory with cURL

Writer Andrew Henderson

I wish for the file to download to ~/downloads and keep the same filename. Then I want that file to be extracted (contents) to the ~/downloads/ok directory. ~/downloads/ok directory exists.

curl -Lo ~/downloads | tar zxf -C ~/downloads/ok

I get the error: tar (child): -C: Cannot open: No such file or directory

2

4 Answers

If you're saving the file to some location in curl, then piping to tar is pointless: there's no data being transferred over the pipe. And the f option in tar is for reading from a file (the filename must be the next argument), so that isn't useful in a pipe either. To save to a file and send to a pipe, use tee:

curl -L | tee ~/downloads/0.1.1.tar.gz | tar zx -C ~/downloads/ok
0

you may want

(cd ~/downloads && curl -L && cd ok && tar zxf ../0.1.1.tar.gz)

or more readably

( f=' cd ~/downloads && curl -L $f && cd ok && tar zxf ../${f##*/}
)

I'm using parentheses to run the commands in a subshell so your current dir in your current shell is not altered

You need to redirect the file itself to the destination directory :

curl -LOk > ~/downloads/0.1.1.tar.gz

And proceed with the archive extraction.

curl -SL | tar -zxC /opt

will produce /opt/abc folder.

The -x for extract, -z for .gz and -C for destination directory,

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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