Save cURL Command Output to a external file


By default when you do an HTTP GET/POST/PUT/DELETE method request using the cURL command, the output is displayed on the console (standard output)

In order to save the output of a cURL command to a file make use of the -o or --output option followed by the filename and the URL.

Example:
% curl -o sample.csv https://code2care.org/sample.csv
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    59  100    59    0     0    621      0 --:--:-- --:--:-- --:--:--   670

% cat sample.csv
1,Sample-1,100
2,Sample-2,200
3,Sample-3,300
4,Sample-4,400
cURL Example to save response as external file

Note: Make use of -O (capital letter O) if you want to save the file as that at the remote location.

Example:
% curl -O https://code2care.org/sample.csv
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    59  100    59    0     0    612      0 --:--:-- --:--:-- --:--:--   655
Save Output to file using cURL Command

Facing issues? Have Questions? Post them here! I am happy to answer!

Author Info:

Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.

Follow him on: X

You can also reach out to him via e-mail: rakesh@code2care.org



















Copyright © Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap