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

查看:4143
本文介绍了使用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?

推荐答案

我不认为您可以提供卷曲的路径,但可以将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 -; }

或使用subshel​​l.

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天全站免登陆