How to Specify a Custom Output Filename in cURL
When downloading files using the command-line utility cURL, saving the file with a specific name rather than its default remote name is a common task. This article explains which cURL flags are used to define a custom output filename, provides practical examples of their usage, and highlights the key differences between the available output options.
The primary flag used to specify a custom output filename in cURL is
the lowercase -o flag (or its long-form
equivalent, --output).
Using the -o
(lowercase) Flag
To save a downloaded file under a specific name, place the
-o flag after the curl command, followed by
your desired filename, and then the URL of the file.
curl -o custom_name.zip https://example.com/download/file_v1.0.zipIn this example, cURL downloads the file from the specified URL but
saves it locally as custom_name.zip instead of
file_v1.0.zip.
Using the
--output Long-form Option
If you prefer more readable scripts, you can use the long-form
equivalent --output in the exact same manner:
curl --output custom_name.zip https://example.com/download/file_v1.0.zipContrast with the
-O (Uppercase) Flag
It is important not to confuse the lowercase -o flag
with the uppercase -O (or
--remote-name) flag.
-o <filename>(Lowercase): Allows you to choose and specify a brand new name for the downloaded file.-O(Uppercase): Forces cURL to save the file using its original, remote filename from the URL (e.g., saving it automatically asfile_v1.0.zipwithout allowing you to rename it during the download).
Downloading Multiple Files with Custom Names
You can also use the -o flag multiple times within a
single command to download different files and assign unique custom
names to each of them:
curl -o local_first.txt https://example.com/first.txt -o local_second.txt https://example.com/second.txt