How to capture response body to a file using curl?

September 13, 2022 No comments curl output capture

1. Introduction

In this short article, we show how to capture curl output to a file..

2. Capture curl output to a file using -o, --output <file> parameter

If we use the -o parameter curl will write output to <file> instead of stdout.

The following command will write output to a file.txt file:

curl "http://example.com/file.txt" -o "file.txt"

3. Save request output to a file using -O parameter

For a single file we could use just -O param instead of -o <file>:

curl http://example.com/file.txt -O

In this approach, the last segment of the URL path will be used as the filename.

4. Conclusion

In this short article, we presented how to capture the output of curl request into a file.

{{ message }}

{{ 'Comments are closed.' | trans }}