152

I am pulling files using curl in the mac OS X terminal and want to give them different names. Is there a way to specify a name, such as a "save as" function when using curl?

Alexis Wilke
  • 19,179
  • 10
  • 84
  • 156
iveytron
  • 1,669
  • 2
  • 12
  • 11
  • 2
    Stack Overflow is a site for programming and development questions. This question appears to be off-topic because it is not about programming or development. See [What topics can I ask about here](http://stackoverflow.com/help/on-topic) in the Help Center. Perhaps [Super User](http://superuser.com/) or [Apple Stack Exchange](http://apple.stackexchange.com/) would be a better place to ask. Also see [Where do I post questions about Dev Ops?](http://meta.stackexchange.com/q/134306). – jww Dec 21 '15 at 05:36

4 Answers4

256

Either use the -o option or its alias --output, or redirect shell output to the file of choice by using >.

curl -o /path/to/local/file http://url.com
curl http://url.com > /path/to/local/file

If you want to preserve the original file name from the remote server, use the -O option or its alias --remote-name.

curl -O http://url.com/file.html 

Stores the output from the remote location in the current directory as file.html.

Cristian Ciupitu
  • 20,270
  • 7
  • 50
  • 76
simonnordberg
  • 2,794
  • 1
  • 16
  • 7
  • Especially helpful given the Chrome "Copy to curl url" feature because an output file name can be appended easily. – rainabba Jun 01 '16 at 23:02
  • 1
    I used this method, but I kept downloading a corrupted file. The issue was that the download URL had a redirect, but adding the `-L` flag (follow redirects) solved my issue. – Nick D Jan 06 '21 at 15:29
24

curl -o <name> <url> seems to do the trick..

HINT: You can also try with man curl...

Tonny Madsen
  • 12,628
  • 4
  • 31
  • 70
2

Here is how to download a file to another file name, and allow redirects. No need to look for -L in the comments.

curl -L "$URL" -o "$FILENAME"

Example

curl -L https://protonmail.com/download/bridge/protonmail-bridge_2.1.1-1_amd64.deb -o bridge.deb

Elijah
  • 1,814
  • 21
  • 27
1

For those who are getting familiar with CURL, here is a more clear and easy to understand use case example:

REMOTE URL

http(s)://my-remote-image.png?token=TOKEN_ID

CURL COMMAND IN ACTION (lowercase "o")

curl -o custom_name_to_be_used.png "http(s)://my-remote-image.png?token=TOKEN_ID"
Hugo Barbosa
  • 85
  • 1
  • 4