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


当前回答

这对我来说很管用:

curl http://centos.mirror.constant.com/8-stream/isos/aarch64/CentOS-Stream-8-aarch64-20210916-boot.iso --output ~/Downloads/centos.iso 

地点:

——output允许我设置我想放置的文件和扩展文件的路径和命名。

其他回答

对于Windows中的powershell,您可以在——output标志中添加相对路径+文件名:

curl -L  http://github.com/GorvGoyl/Notion-Boost-browser-extension/archive/master.zip --output build_firefox/master-repo.zip

这里build_firefox是相对文件夹。

——output-dir选项从curl 7.73.0开始就可用了:

curl --create-dirs -O --output-dir /tmp/receipes https://example.com/pancakes.jpg

使用wget

wget -P /your/absolut/path "https://jdbc.postgresql.org/download/postgresql-42.3.3.jar"

Curl没有这样的选项(没有指定文件名),但wget有。目录可以是相对目录,也可以是绝对目录。此外,如果目录不存在,则会自动创建该目录。

wget -P relative/dir "$url"

wget -P /absolute/dir "$url"

对于Windows,在PowerShell中,curl是cmdlet Invoke-WebRequest的别名,这个语法是有效的:

curl "url" -OutFile file_name.ext

例如:

curl "https://airflow.apache.org/docs/apache-airflow/2.2.5/docker-compose.yaml" -OutFile docker-compose.yaml

来源:https://krypted.com/windows-server/its-not-wget-or-curl-its-iwr-in-windows/