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 on the screen. When using Curl, you must explicitly request that the downloaded resource be saved to disk by using the --output (-o) or --remote-name (-O) command-line options. The file will be saved to the current directory that you are working in. 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.
If you want to give the downloaded file a specific name, you must use the --output or -o option with the following syntax:
Curl Download File Syntax
curl -o [file name] [URL]
Curl Download File Example
The following is an example of downloading a file using Curl:
Curl Download File
curl -o page.html https://reqbin.com/echo
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. Below is an example of downloading a file using Curl, keeping its original name:
Use Remote File Name
curl -O [URL]
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. Below is an example of downloading multiple files using Curl:
By default, Curl shows no progress when downloading a file. To see the download progress, use the "-#" flag. The following is an example of printing download progress using the Curl flag:
Curl Shoe Download Progress
curl -# -O [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. Below is an example of silent downloading of a file in Curl:
Curl Silent Download Mode
curl -s -O [URL]
How to limit download speed 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 speed in kilobytes, add the suffix "k" or "K", or "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.