curl
has the -o
, --output
option which takes a single argument indicating the filename output should be written to instead of stdout
. If you are using {}
or []
to surround elements in the URL (usually used to fetch multiple documents), you can use #
followed by a number in the filename specifier. Each such variable will be replaced with the corresponding string for the URL being fetched. To fetch multiple files, add a comma-separated list of tokens inside the {}
. If parts of the URLs to be fetched are sequential numbers, you can specify a range with []
.
Examples:
curl http://www.abc.com/123/{def}/{ghi}/{jkl}.mno -o '#1_#2_#3.mno'
Note the quotes around the option argument (not needed unless the the filename starts with one of the expanded variables).
This should result in the output file def_ghi_jkl.mno
.
curl http://www.abc.com/123/{def}/{ghi}/{jkl,pqr,stu}.mno -o '#1_#2_#3.mno'
This should result in the output files def_ghi_jkl.mno
, def_ghi_pqr.mno
and def_ghi_stu.mno
.
curl http://www.abc.com/123/{def}/{ghi}/[1-3].mno -o '#1_#2_#3.mno'
This should result in the output files def_ghi_1.mno
, def_ghi_2.mno
, def_ghi_3.mno
.