如何让 curl 将文件保存到指定目录?

16 command-line-interface curl

我正在尝试使用脚本获取 curl 来下载文件并将其保存到某个目录。我下载了它,但我不知道如何从脚本中将它下载到某个目录。它通常只是将其保存到当前工作目录。

Mik*_*ike 17

curl http://google.com > /path/to/dir/index.html
Run Code Online (Sandbox Code Playgroud)


ant*_*yer 8

更正:

您可以使用

-o, --output FILE 将输出写入而不是 stdout

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

  • 这不能回答问题。 (2认同)
  • -o 的文档说: >> 文件将保存在当前工作目录中。如果您希望将文件保存在不同的目录中,请确保在使用此选项调用curl 之前更改当前工作目录。 (2认同)