Velvet Star Monitor

Standout celebrity highlights with iconic style.

general

How to capture cURL output to a file?

Writer Andrew Mclaughlin

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?

1

10 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.

6

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 -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.

3

There are several options to make curl output to a file

 # saves it to myfile.txt
curl -o myfile.txt
# The #1 will get substituted with the url, so the filename contains the url
curl -o "file_#1.txt"
# saves to data.txt, the filename extracted from the URL
curl -O
# saves to filename determined by the Content-Disposition header sent by the server.
curl -O -J 

Either curl or wget can be used in this case. All 3 of these commands do the same thing, downloading the file at and saving it locally into "my_file.txt":

wget -O my_file.txt # my favorite--it has a progress bar
curl -o my_file.txt
curl > my_file.txt

Notice the first one's -O is the capital letter "O".

The nice thing about the wget command is it shows a nice progress bar.

You can prove the files downloaded by each of the 3 techniques above are exactly identical by comparing their sha512 hashes. Running sha512sum my_file.txt after running each of the commands above, and comparing the results, reveals all 3 files to have the exact same sha hashes (sha sums), meaning the files are exactly identical, byte-for-byte.

See also: wget command to download a file and save as a different filename

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 | pbcopy. This will copy all the content from the given URL to your clipboard.

Linux version: curl | xclip

Windows version: curl | clip

2

Use --trace-ascii output.txt to output the curl details to the file output.txt.

1

If you want to store your output into your desktop, follow the below command using post command in git bash.It worked for me.

curl --request POST --header "Content-Type: application/json" -o "C:\Desktop\test.txt"
0

A tad bit late, but I think the OP was looking for something like:

curl -K myfile.txt --trace-ascii output.txt
0

You need to add quotation marks between "URL" -o "file_output" otherwise, curl doesn't recognize the URL or the text file name.

Format

curl "url" -o filename

Example

curl "" -o output_file.txt

Example_2

curl "" > output_file.txt 

Just make sure to add quotation marks.

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

curl -K myconfig.txt >> output.txt

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy