Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to download a file using curl

I'm on mac OS X and can't figure out how to download a file from a URL via the command line. It's from a static page so I thought copying the download link and then using curl would do the trick but it's not.

I referenced this StackOverflow question but that didn't work. I also referenced this article which also didn't work.

What I've tried:

curl -o https://github.com/jdfwarrior/Workflows.git curl: no URL specified! curl: try 'curl --help' or 'curl --manual' for more information 

.

wget -r -np -l 1 -A zip https://github.com/jdfwarrior/Workflows.git zsh: command not found: wget 

How can a file be downloaded through the command line?

like image 935
Alex Cory Avatar asked Apr 02 '14 01:04

Alex Cory


People also ask

How do I download files using curl Windows?

To download a file with Curl, use the --output or -o command-line option. This option allows you to save the downloaded file to a local drive under the specified name. If you want the uploaded file to be saved under the same name as in the URL, use the --remote-name or -O command line option.

How do I download multiple files with curl?

Download multiple files simultaneously Instead of downloading multiple files one by one, you can download all of them simultaneously by running a single command. To download multiple files at the same time, use –O followed by the URL to the file that you wish to download. The above command will download both files.

Where does curl download to?

Consequentially, the file will be saved in the current working directory. If you want the file saved in a different directory, make sure you change current working directory before you invoke curl with the -O, --remote-name flag!


2 Answers

The -o --output option means curl writes output to the file you specify instead of stdout. Your mistake was putting the url after -o, and so curl thought the url was a file to write to rate and hence that no url was specified. You need a file name after the -o, then the url:

curl -o ./filename https://github.com/jdfwarrior/Workflows.git 

And wget is not available by default on OS X.

like image 180
jfly Avatar answered Sep 30 '22 15:09

jfly


curl -OL https://github.com/jdfwarrior/Workflows.git 

-O: This option used to write the output to a file which named like remote file we get. In this curl that file would be Workflows.git.

-L: This option used if the server reports that the requested page has moved to a different location (indicated with a Location: header and a 3XX response code), this option will make curl redo the request on the new place.

Ref: curl man page

like image 20
Buddhi Avatar answered Sep 30 '22 14:09

Buddhi