curl command examples in Linux in details

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.
# curl –F “file=/tmp/file.txt” https://example.com/upload
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.
# curl --limit-rate 100K  https://example.com/file.zip
There is option “-X” by using this you can send custom HTTP 
requests with methods like GET, POST, DELETE, PUT etc.
# curl -X GET https://example.com/resources
If your environment having a proxy then you can also use proxy 
to go out via curl command.
# curl –x https://proxyserver:port https://example.com
Let’s send a data from a file to the URL.
# curl –d @file.txt https://example.com
If you want to save cookies and process in the other sequence 
then you can do it via below commands.
# curl –c cookies-file.txt https://example.com
# curl –b cookies-file.txt https://example.com/resources
In some case, you will also get FTP link from where you need to 
upload file and there you can go ahead and use below command.
# curl –T /tmp/test.txt ftp://example.com –user username:password

# curl –T /tmp/test.txt https://example.com/upload	(using PUT method)
Go through man page of curl command and you will find many 
possibilities to find details about URLs and helps in 
troubleshooting various WEB issues. 

Keep exploring. Continue reading on our blog.

More Commands

Leave a Reply

Your email address will not be published. Required fields are marked *