How to capture cURL output to a file? How to capture cURL output to a file? curl curl

How to capture cURL output to a file?


curl -K myconfig.txt -o output.txt 

Writes the first output received in the file you specify (overwrites if an old one exists).

curl -K myconfig.txt >> output.txt

Appends all output you receive to the specified file.

Note: The -K is optional.


For a single file you can use -O instead of -o filename to use the last segment of the URL path as the filename. Example:

curl http://example.com/folder/big-file.iso -O

will save the results to a new file named big-file.iso in the current folder. In this way it works similar to wget but allows you to specify other curl options that are not available when using wget.


There are several options to make curl output to a file

 # saves it to myfile.txtcurl http://www.example.com/data.txt -o myfile.txt# The #1 will get substituted with the url, so the filename contains the urlcurl http://www.example.com/data.txt -o "file_#1.txt" # saves to data.txt, the filename extracted from the URLcurl http://www.example.com/data.txt -O # saves to filename determined by the Content-Disposition header sent by the server.curl http://www.example.com/data.txt -O -J