使用 curl 命令将文件保存到特定文件夹 [英] Save file to specific folder with curl command

查看:256
本文介绍了使用 curl 命令将文件保存到特定文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 shell 脚本中,我想从某个 URL 下载文件并将其保存到特定文件夹.使用 curl 命令将文件下载到特定文件夹时应该使用的特定 CLI 标志是什么,或者我如何获得该结果?

In a shell script, I want to download a file from some URL and save it to a specific folder. What is the specific CLI flag I should use to download files to a specific folder with the curl command, or how else do I get that result?

推荐答案

我觉得你不能给curl的路径,但是你可以CD到那个位置,下载然后CD回来.

I don't think you can give a path to curl, but you can CD to the location, download and CD back.

cd target/path && { curl -O URL ; cd -; }

或者使用子shell.

Or using subshell.

(cd target/path && curl -O URL)

两种方式都只会在路径存在时下载.-O 保留远程文件名.下载后会回到原来的位置.

Both ways will only download if path exists. -O keeps remote file name. After download it will return to original location.

如果需要显式设置文件名,可以使用小的-o选项:

If you need to set filename explicitly, you can use small -o option:

curl -o target/path/filename URL

这篇关于使用 curl 命令将文件保存到特定文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆