Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to capture cURL output to a file?

I have a text document that contains a bunch of URLs in this format:

URL = "sitehere.com" 

What I'm looking to do is to run curl -K myfile.txt, and get the output of the response cURL returns, into a file.

How can I do this?

like image 997
Tony Avatar asked Dec 06 '12 00:12

Tony


People also ask

How do I redirect a curl output to a file?

For those of you want to copy the cURL output in the clipboard instead of outputting to a file, you can use pbcopy by using the pipe | after the cURL command. Example: curl https://www.google.com/robots.txt | pbcopy . This will copy all the content from the given URL to your clipboard.

How do I save a curl script?

We can save the result of the curl command to a file by using -o/-O options. Now the page gettext. html will be saved in the file named 'mygettext.

Where does curl output go?

Consequentially, the file will be saved in the current working directory. If you want the file saved in a different directory, make sure you change current working directory before you invoke curl with the -O, --remote-name flag! There is no URL decoding done on the file name.

How do I print a curl response?

By default, curl doesn't print the response headers. It only prints the response body. To print the response headers, too, use the -i command line argument.


2 Answers

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.

like image 83
Alex2php Avatar answered Sep 17 '22 14:09

Alex2php


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.

like image 45
Greg Bray Avatar answered Sep 20 '22 14:09

Greg Bray