Download file extract to specific directory with cURL
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/okI get the error: tar (child): -C: Cannot open: No such file or directory
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.gzAnd proceed with the archive extraction.
curl -SL | tar -zxC /optwill produce /opt/abc folder.
The -x for extract, -z for .gz and -C for destination directory,