Here is how to install curl on macOS/Windows/Linux
https://help.ubidots.com/en/articles/2165289-learn-how-to-install-run-curl-on-windows-macosx-linux
get ipinfo
We can get an IP address with curl command easily.
$ curl ipinfo.io
{
"ip": "xxx.xxx.xxx.xxx",
"hostname": "cpe-xxx-xxx-xxx-xxx.xxs.sss.sss.com",
"city": "Brooklyn",
"region": "New York",
"country": "US",
"loc": "xx.aaaa,yy.bbbb",
"org": "TTTTT Inc",
"postal": "xxxxx",
"timezone": "America/New_York",
"readme": "https://ipinfo.io/missingauth"
}%
generate QR code
The following is a QR code to access my personal website./
you can put anything you want to show(string, number, and url).
$ curl qrenco.de/https://kojikoji.ga
βββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββ
ββββ βββββ βββββββ ββ βββββ ββββ
ββββ β β βββββββββββ β β ββββ
ββββ βββββ βββββ ββ β βββββ ββββ
ββββββββββββ βββββ ββββββββββββββ
βββββββββββ ββββ βββ ββββββββββ
βββββββ β ββββ β βββββ βββ βββββ
βββββββ ββ ββ ββββ ββ ββ ββββ
βββββββββββββ βββββββββββββ βββββ
ββββββββββββ βββ ββ βββ βββββββ
ββββ βββββ β βββ β β βββ β βββββ
ββββ β β ββββ ββ β ββ βββββββ
ββββ βββββ β βββββββββ ββββββββ
βββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββ
get weather info
If you change after /
, you can see the weather that you want to know.
$ curl wttr.in/newyork
Weather report: newyork \ / Clear
.-. +33(28) Β°F
β ( ) β β 0 mph
`-β 9 mi
/ \ 0.0 in
βββββββββββββββ
ββββββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββ€ Sun 21 Feb βββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββ
β Morning β Noon ββββββββ¬βββββββ Evening β Night β
ββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββ€
β \ / Sunny β \ / Sunny β \ / Partly cloudy β Cloudy β
β .-. 21(12) Β°F β .-. 30(21) Β°F β _ /"".-. +33(28) Β°F β .--. 28(21) Β°F β
β β ( ) β β 9-14 mph β β ( ) β β 8-9 mph β \_( ). β 4-6 mph β .-( ). β 5-8 mph β
β `-β 6 mi β `-β 6 mi β /(___(__) 6 mi β (___.__)__) 6 mi β
β / \ 0.0 in | 0% β / \ 0.0 in | 0% β 0.0 in | 0% β 0.0 in | 0% β
ββββββββββββββββββββββββββββββββ΄βββββββββββββββββββββββββββββββ΄βββββββββββββββββββββββββββββββ΄βββββββββββββββββββββββββββββββ
βββββββββββββββ
ββββββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββ€ Mon 22 Feb βββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββ
β Morning β Noon ββββββββ¬βββββββ Evening β Night β
ββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββ€
β Overcast β .-. Light sleet β .-. Moderate rain β Overcast β
β .--. 32(23) Β°F β ( ). +35(26) Β°F β ( ). +33(28) Β°F β .--. 26 Β°F β
β .-( ). β 11-18 mph β (___(__) β 11-16 mph β (___(__) β 10-17 mph β .-( ). β 7-13 mph β
β (___.__)__) 3 mi β β * β * 6 mi β ββββββββ 4 mi β (___.__)__) 4 mi β
β 0.0 in | 0% β * β * β 0.0 in | 29% β ββββββββ 0.2 in | 56% β 0.1 in | 0% β
ββββββββββββββββββββββββββββββββ΄βββββββββββββββββββββββββββββββ΄βββββββββββββββββββββββββββββββ΄βββββββββββββββββββββββββββββββ
βββββββββββββββ
ββββββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββ€ Tue 23 Feb βββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββ
β Morning β Noon ββββββββ¬βββββββ Evening β Night β
ββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββ€
β \ / Partly cloudy β Overcast β \ / Clear β \ / Partly cloudy β
β _ /"".-. 32(23) Β°F β .--. +35(26) Β°F β .-. +37(30) Β°F β _ /"".-. +35(28) Β°F β
β \_( ). β 9-14 mph β .-( ). β 11-15 mph β β ( ) β β 11-18 mph β \_( ). β 11-19 mph β
β /(___(__) 6 mi β (___.__)__) 6 mi β `-β 6 mi β /(___(__) 6 mi β
β 0.0 in | 0% β 0.0 in | 0% β / \ 0.0 in | 0% β 0.0 in | 0% β
ββββββββββββββββββββββββββββββββ΄βββββββββββββββββββββββββββββββ΄βββββββββββββββββββββββββββββββ΄βββββββββββββββββββββββββββββββ
get cryptocurrency rate
The rate.sx
shows you famous currencies' rate. If you put a specific currency, you can see the rate and a chart of the currency.
$ curl rate.sx# if you want to see a specific currency, you can type curl rate.sx/etc _
_ _ __ _| |_ ___ ____ __
| '_/ _` | _/ -_)(_-< \ /
__................................................__________|_| \__,_|\__\___()__/_\_\_____
' ' ' ' 'Market Cap: $1,693,391,363,316 =
24h Vol: $141,903,885,617 =
BTC Dominance: 61.7% =
ββββββββ¬βββββββ¬ββββββββββββββ¬βββββββββββββββ¬ββββββββββββββ¬βββββββββββββββββββ¬βββββββββββββββ
β Rank β Coin β Price (USD) β Change (24H) β Change (1H) β Market Cap (USD) β Spark (1H) β
ββββββββΌβββββββΌββββββββββββββΌβββββββββββββββΌββββββββββββββΌβββββββββββββββββββΌβββββββββββββββ€
β 1 β BTC β 55806.9 β -1.43% β -0.84% β 1.040T β ββββββββ ββ ββ β
ββββββββΌβββββββΌββββββββββββββΌβββββββββββββββΌββββββββββββββΌβββββββββββββββββββΌβββββββββββββββ€
β 2 β ETH β 1856.99 β -4.33% β -1.30% β 213.128B β ββββββββββββ β
ββββββββΌβββββββΌββββββββββββββΌβββββββββββββββΌββββββββββββββΌβββββββββββββββββββΌβββββββββββββββ€
β 3 β BNB β 275.070 β 4.42% β -1.05% β 42.507B β βββββ βββ β βββ β
ββββββββΌβββββββΌββββββββββββββΌβββββββββββββββΌββββββββββββββΌβββββββββββββββββββΌβββββββββββββββ€
β 4 β USDT β 0.999895 β -0.00% β 0.00% β 34.254B β ββββββββ ββββ β
ββββββββΌβββββββΌββββββββββββββΌβββββββββββββββΌββββββββββββββΌβββββββββββββββββββΌβββββββββββββββ€
β 5 β DOT β 37.5132 β -3.17% β -0.78% β 34.148B β βββββββ βββ ββ β
ββββββββΌβββββββΌββββββββββββββΌβββββββββββββββΌββββββββββββββΌβββββββββββββββββββΌβββββββββββββββ€
β 6 β ADA β 1.03773 β -5.29% β -1.04% β 32.286B β ββββββ βββ βββ β
ββββββββΌβββββββΌββββββββββββββΌβββββββββββββββΌββββββββββββββΌβββββββββββββββββββΌβββββββββββββββ€
β 7 β XRP β 0.526163 β 0.60% β -1.01% β 23.890B β ββββββββββββ β
ββββββββΌβββββββΌββββββββββββββΌβββββββββββββββΌββββββββββββββΌβββββββββββββββββββΌβββββββββββββββ€
β 8 β LTC β 217.838 β -3.43% β -2.08% β 14.493B β ββββββββ β ββ β β
ββββββββΌβββββββΌββββββββββββββΌβββββββββββββββΌββββββββββββββΌβββββββββββββββββββΌβββββββββββββββ€
β 9 β LINK β 32.0389 β -5.71% β -1.67% β 13.088B β ββ ββββ ββββββ β
ββββββββΌβββββββΌββββββββββββββΌβββββββββββββββΌββββββββββββββΌβββββββββββββββββββΌβββββββββββββββ€
β 10 β BCH β 676.781 β -0.68% β -1.11% β 12.630B β ββββββ ββ β βββ β
ββββββββ΄βββββββ΄ββββββββββββββ΄βββββββββββββββ΄ββββββββββββββ΄βββββββββββββββββββ΄βββββββββββββββ
2021-02-22 04:40:23.577769 UTC$ curl rate.sx/ethβΆ Ethereum (ETH) βΆ Sun 21 +1d -4.35% β 1970.0
β β‘ β’ β £β‘ β‘β β’£
β β‘ β’β Ό β β β£β‘ β’°β β’£
β β‘ β‘ β β’£β’£ β‘ β β ²β‘β£ β£ β‘Έ β β‘
β β‘ β’°β β β‘ β’Έβ‘β‘ β β β£β β£β‘β‘β’ β‘ β‘
β β‘ β’Έ β £β‘ β‘β‘⣧β β’Ή β β β β’± β °β β’¨
β β‘β’°β‘ β‘ β‘ β β ³β β β‘
β β‘Ώβ‘β β β Έβ‘ β’°β‘ β’β‘ β‘
β β β’β‘β‘β’ β’°β‘β β’β β’β‘ β‘ β‘
β β β’±β β’Έ β’Έβ£β β β β’Έ β’ β‘ β£³
β β’Έ β’Έβ Ή β β β β’Ώβ’ β’ β’°β β β’Έ
β β’Έ β‘ β Έβ‘β’Έ β‘ β β‘
β β‘β‘β‘ β β β‘β‘ β‘β£ β’
β β β’Έβ β£β β β β‘ β’ β β‘ β£»
β β£· β‘ β’Έ β’±β’β β’
β β β’£ β‘ β’Έβ’Έ β β‘
β β’Έβ‘β β β Έβ‘
β β Έβ β‘
β β’±
β β’Έβ’
β β ¨β£Ώ
β β β‘β‘
β β‘β£·
β β’³β Ήβ‘
β β β‘
β β‘
β 1860.0
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββbegin: $1941.5 (Sun 21 04:50) // end: $1857.0 (Mon 22 04:40)
high: $1973.9 (Sun 21 19:40) // low: $1857.0 (Mon 22 04:40)
avg: $1938.5 // median: $1915.5 // change: -84.524 (-4.35%)
Use @ for interval specification: /btc@10d, /eth@4w, /xrp@January (more in /:help)
Watch animation on Terminal
$ curl ascii.live/nyan.,
.. ;
;' c
.... ;
......... .,:.........................
,,,;;;;;;;;;,,,,,,,,,;;;;;;.c0KK00000O00O0000KKKo
oooxxxxxxxxxoooooooodxxxxxx.oK0kx000Ok00kxxk0O0Kk
kkk000000000kkkkkkkkO000000.o0000000O000c;;:cx00k ';
XXXXXXXXXXXXXXXXXXXXXXXXXXX.o0000O0Ox000':ddl;;;; ;odd.
OOOkxxxxxxxkOOOOOOOOOxxxx;, o000Ok00Ox0c,ldxdddddddxdd:.
xxxdddddddddxxxxxxxxxl;;;oo o0kk00000O0.:ddo,'ddo;dl.:d,
lllcccccccccllllllll;.ol .. oK0Ok0Ox000.:kOxc:do;od,ckO;
::::;;;;;;;:::::::::;'''';; ;0K0O000000kc:odc.,'.,,.cc.
;;,.........,;;;;;;;,..... :c'..';,...cc'..',....;'..
.. . ''k: . ..
, .:
.. ,
'; o
.. ' ,
.
..
..
;' .c lk
get a page
$ $ curl https://google.com
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="https://www.google.com/">here</A>.
</BODY></HTML># save as a html
$ curl -o google.html https://google.com# get only header info
$ curl --head https://google.com
HTTP/2 301
location: https://www.google.com/
content-type: text/html; charset=UTF-8
date: Mon, 22 Feb 2021 09:26:54 GMT
expires: Wed, 24 Mar 2021 09:26:54 GMT
cache-control: public, max-age=2592000
server: gws
content-length: 220
x-xss-protection: 0
x-frame-options: SAMEORIGIN
alt-svc: h3-29=":443"; ma=2592000,h3-T051=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43"
get method
In this case, I used https://openweathermap.org/ with jq (I will post an article on jq soon).
$ curl "https://api.openweathermap.org/data/2.5/weather?q=London&appid=your_api_key&units=metric" | jq % Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 469 100 461 100 8 2727 47 --:--:-- --:--:-- --:--:-- 2775
{
"coord": {
"lon": -0.1257,
"lat": 51.5085
},
"weather": [
{
"id": 804,
"main": "Clouds",
"description": "overcast clouds",
"icon": "04n"
}
],
"base": "stations",
"main": {
"temp": 8.79,
"feels_like": 7.31,
"temp_min": 7.78,
"temp_max": 10,
"pressure": 1011,
"humidity": 87
},
"visibility": 10000,
"wind": {
"speed": 1.03,
"deg": 0
},
"clouds": {
"all": 100
},
"dt": 1613974910,
"sys": {
"type": 1,
"id": 1414,
"country": "GB",
"sunrise": 1613977229,
"sunset": 1614014870
},
"timezone": 0,
"id": 2643743,
"name": "London",
"cod": 200
}
post method
$ curl -d "param1=aaa¶m=bbb" https://api.com
post json
$ curl -H "Content-Type: application/json" \
-d '{"key": "value"}' https://api.com# with @ we can load a file
$ curl -H "Content-Type: application/json" \
-d @params.json https://api.com
Basic auth
$ curl -u id:password https://example.com
use Bearer
$ curl -H 'Authorization: Bearer xxxxxxxx' https://api.com
generate a curl command from Google Chrome
Open DevTool > Network > right click name
> copy > copy as cURL
or copy all as cURL
curl 'chrome-extension://jlmpjdjjbgclbocgajdjefcidcncaied/index.html' --compressed ;
curl 'chrome-extension://jlmpjdjjbgclbocgajdjefcidcncaied/css/home.94d1d1b7.css' \
-H 'Referer: ' \
-H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 11_2_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36' \
-H 'DNT: 1' \
--compressed ;
curl 'chrome-extension://jlmpjdjjbgclbocgajdjefcidcncaied/css/standalone/standalone.723be05a.css' \
-H 'Referer: ' \
-H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 11_2_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36' \
-H 'DNT: 1' \
--compressed ;
curl 'chrome-extension://jlmpjdjjbgclbocgajdjefcidcncaied/js/home.home.js' \
-H 'Referer: ' \
-H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 11_2_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36' \
-H 'DNT: 1' \
--compressed ;
curl 'chrome-extension://jlmpjdjjbgclbocgajdjefcidcncaied/standalone/stand
--compressed
Send Cookie
$ curl -b 'key=value; key2=value2;' https://test.cookie.com
$ curl --cookie 'key=value; key2=value2;' https://test.cookie.com
Save Cookie
$ curl -c cookie.txt https://test.cookie.com
Send back Cookie
Send back stored cookie file, cookie.txt
$ curl -b cookie.txt https://test.cookie.com
Upload file
$ curl -F file_name=@sample.txt https://uploader.com
measure the response (benchmark)
$ curl https://dev.to -s -o /dev/null -w "%{time_total}\n"
0.150539
Only one-time measurement doesnβt make sense lol
The following is do the same thing 10 times and calc the average.
$ for i in {1..10}; do curl https://dev.to -s -o /dev/null -w "%{time_total}\n";done | awk '{sum+=$1;print $1} END {print "AVG: " sum/NR}'
0.464525
0.132371
0.136095
0.137686
0.143925
0.132686
0.141533
0.122407
0.131222
0.162784
AVG: 0.170523