Save file to specific folder with curl command

后端 未结 4 1971
北荒
北荒 2020-12-07 07:56

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 folde

相关标签:
4条回答
  • 2020-12-07 08:27

    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 -; }
    

    Or using subshell.

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

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

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

    curl -o target/path/filename URL
    
    0 讨论(0)
  • 2020-12-07 08:30

    This option comes in curl 7.73.0:

    curl --create-dirs -O --output-dir /tmp/receipes https://example.com/pancakes.jpg
    
    0 讨论(0)
  • 2020-12-07 08:31

    For powershell in Windows, you can add relative path + filename to --output flag:

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

    here build_firefox is relative folder.

    0 讨论(0)
  • 2020-12-07 08:39

    curl doesn't have an option to that (without also specifying the filename), but wget does. The directory can be relative or absolute. Also, the directory will automatically be created if it doesn't exist.

    wget -P relative/dir "$url"
    
    wget -P /absolute/dir "$url"
    
    0 讨论(0)
提交回复
热议问题