To save the output of a cURL command to a file we have multiple options:
curl http://e.com -o file.txt
curl http://e.com > file.txt
First one uses the -o
or --output
option followed by the file name. The second one redirects the command output to a file.
Example cURL -o
Here are few examples:
curl https://softhints.com -o file.txt
The output of the cURL command is saved to a file named file.txt.
Example cURL > file
As alternative we can use the >
operator to redirect the output to a file:
curl http://e.com > file.txt
I prefer to use this one when I do multiple cURL requests in parallel.
Keep origin name
To keep the original name of the target URL we can use -O
:
curl http://e.com/data.txt -O
This will save the output to file named data.txt
Example cURL to clipboard
What if you like to save the cURL output to a clipboard? To save cURL command results to clipboard we can redirect the output to clipboard with tool like xclip
:
curl https://softhints.com | xclip
To install xclip
in Linux you can use your terminal - sudo apt-get install xclip
All of these methods will save the output of the cURL command to a file. It depends on your needs what you will choose.