19

I'm trying to get curl, using a script, to download a file and save it to a certain directory. I got it to download but I dont know how to get it to a certain directory from a script. It usually just saves it to the current working directory.

  • This question appears to be off-topic because it is about a typical User use-case, not directly related to System Administration. Questions like this should be asked on [unix.SE]. This question is too old to migrate there. – Chris S May 02 '14 at 13:05
  • 1
    @ChrisS This doesn't make sense to me. System administrators constantly use curl and other tools to download to a specified directory. It is a fundamental part of system administration. – rjurney Nov 22 '19 at 22:38

3 Answers3

22
curl http://google.com > /path/to/dir/index.html
Mike
  • 22,310
  • 7
  • 56
  • 79
10

CORRECTION:

You can use

-o, --output FILE Write output to instead of stdout

curl --url https://google.com --output /any/file-location

antonydenyer
  • 209
  • 2
  • 5
  • 3
    This doesn't answer the question. – Andrew Schulman May 02 '14 at 10:51
  • 2
    Documentation for -o says: >> The file will be saved in the current working directory. If you want the file saved in a different directory, make sure you change the current working directory before invoking curl with this option. – meglio Dec 01 '17 at 11:01
2

Let curl and the shell each do what they do well:

(cd TARGET_DIRECTORY && curl ...)

Also there may be things that interest you in the description of the -o option in the manual.