To download a file with Curl, use the --output or -o command-line option. This option allows you to save the downloaded file to a local drive under the specified name. If you want the uploaded file to be saved under the same name as in the URL, use the --remote-name or -O command line option. If you don't use any of these options, Curl will print the downloaded file content to the screen. In this Curl Download File example, we download a file from the ReqBin echo URL. For security reasons, saving files on the ReqBin server is disabled.
By default, when you request a resource from the server using Curl, it downloads the resource and displays its contents to the screen. If you want Curl to save the downloaded resource to disk, you must explicitly tell Curl to do so using one of the --output (-o) or --remote-name (-O) command-line options. The file will be saved in the current working directory. To save the file in a different directory, change the working directory before running the Curl command. If the file already exists, it will be overwritten.
Curl Download File Syntax
If you want to give the downloaded file a specific name, you must use the --output or -o option with the following syntax:
Download File Syntax
curl -o [file name] [URL]
How to save the file with its original name?
To save the downloaded file with the same name as specified in the URL, use the --remote-name (or -O) command line parameter. Curl will only take file part and ignore the path.
Use Remote File Name
curl -O [URL]
Curl Download File Example
Example of downloading a file from ReqBin echo URL:
Curl Download File
curl -o page.html https://reqbin.com/echo
How to download multiple files using Curl?
To download multiple files using Curl, you can specify multiple URLs and filenames in one Curl command. Curl will save the first URL under the first file name, the second URL under the second file name, etc.
By default, Curl shows no progress when downloading a file. To display the progress bar, use the "- #" flag.
Curl Shoe Download Progress
curl -# -o [file name] [URL]
How to enable silent download mode in Curl?
If you don't want to see any information while downloading the file, you can turn on silent mode to prevent Curl from printing anything. The silent mode can be enabled with the --silent (-s) command-line parameter. This can be useful when using Curl in automation scripts.
Curl Silent Download Mode
curl -s -O [URL]
How to limit download speeds in Curl?
Curl allows you to limit the maximum download speed using the –limit-rate flag. This can be useful when using Curl on slow internet connections. Download speed is measured in bytes per second. If you want to specify the rate in kilobytes, add the suffix "k", "K", "m", or "M" for megabytes. The suffixes (k, M, G) are 1024 in size. In this Curl Download File example, we limit the download speed to 100 kilobytes per second.