In world of Linux, you must know various commands. One of them is “curl”. It is very powerful utility and helps in playing with URLs. It supports a wide range of protocols. It is used to transferring the data with URLs. Let’s have a look to its examples.
Its syntax is “curl [option] [URL]”.
A very simple GET response you can get from below command. You can use protocol you are looking for. If we are opening a HTTP/HTTPS then it will print a html output of the URL you have mentioned.
# curl https://example.com
If you want to see in details then you can use verbose.
# curl –v https://example.com
If you want to save output of above command to file then you can use option “-o” with output filename. It will show you details of transfer data as well. And if you want to download in form of zip file then you can use “-O”. The “-O” can also be used to download files.
# curl https://example.com -o example.html
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 77914 0 77914 0 0 34876 0 --:--:-- 0:00:02 --:--:-- 34923
# curl -O https://example.com/example.zip
The below command is useful to follow if there is any new location for the requested URL. Or you can simply understand it to follow the redirection of URL.
# curl -L https://example.com
Sometimes you need to run commands in silent mode then you can use –silent or –s as option.
# curl --silent https://example.com
If you want to upload some data to the URL then use “-F” option.
If your URL is having some authentication then you need to specify the credential to it.
# curl –u username:password https://example.com
Let’s say you want to limit the download speed then you can also achieve this by curl.If there are URL needs authentication to download then you can also use 2nd option with below command to download it.