8

With curl is possible do

curl http://somedomain.com/originalfilename.tar.gz -o newfilename.tar.gz
curl http://somedomain.com/originalfilename.tar.gz -o /other/path/newfilename.tar.gz

Therefore with -o is possible rename the filename to download and even define other path directort to download

Now if I want keep the same filename is mandatory use -O

curl http://somedomain.com/originalfilename.tar.gz -O

Therefore is downloaded the originalfilename.tar.gz file.

Now

Question

  • How to download a file keeping its name (it with -O) and defining the directory to download?

Something like

curl http://somedomain.com/originalfilename.tar.gz -O <download to /some/path>

Therefore for Shell Scripting purposes, where the script can be executed in any place. I want download the originalfilename.tar.gz file explicitly at /some/path

1 Answer 1

13

You may specify the path to a directory where the document(s) you are fetching should be written using the --output-dir option.

That is,

curl -O --output-dir /some/path "$URL"

From the curl manual:

--output-dir <dir>

       This option specifies the directory in which files should be
       stored, when --remote-name or --output are used.

       The given output directory is used for all URLs and output
       options on the command line, up until the first -:, --next.

       If the specified target directory does not exist, the operation
       will fail unless --create-dirs is also used.

       If this option is used multiple times, the last specified
       directory will be used.

       Example:
        curl --output-dir "tmp" -O https://example.com

       See also -O, --remote-name and -J, --remote-header-name. Added
       in 7.73.0.
0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.