The curl command in Linux is an impressive application that’s used to switch records from or to a community server, leveraging a wide selection of protocols like HTTP, HTTPS, FTP, and SFTP.

In more practical phrases, it’s a device that is helping you switch records over the web immediately out of your command line. As an example, you’ll use curl to obtain a document from a URL, or add a document to a server.

This command-line device is not only about shifting information. You’ll additionally use curl to make HTTP requests, equivalent to GET and POST, out of your terminal. That is extraordinarily helpful when trying out or interacting with internet services and products and APIs. With curl, you’ll even check up on the content material of a internet web page with out in truth opening it in a browser, as it may well fetch and show the uncooked records.

Listed here are some alternative ways to make use of the curl command:

Elementary Utilization

The most simple approach to make use of curl is to sort curl adopted by way of the URL of the web page you need to get entry to.

curl http://instance.com

Whilst you run the command curl http://instance.com within the terminal, it sends a GET request to the server situated at http://instance.com. The output that you simply see at the terminal is the server’s reaction to this GET request, most often the HTML content material of the webpage.

1. Save Output to a Document

Via default, curl outputs the supply of the web page that you simply asked. If you wish to save this output to a document, you’ll use the -o or -O choice.

curl -o output.html http://instance.com

The -o choice lets you specify a filename, whilst -O will use the filename from the URL.

2. Observe Redirects

If the URL you’ve asked redirects to every other web page, curl gained’t practice the redirect until you come with the -L choice.

curl -L http://instance.com
3. Ship POST Requests

You’ll use curl to ship POST requests. That is ceaselessly used when filing paperwork.

curl -d "param1=value1¶m2=value2" -X POST http://instance.com/sort

The -d choice tells curl that you simply’re going to ship POST records, and the -X choice specifies the request way to make use of.

4. Ship GET Requests with Parameters

You’ll ship a GET request with parameters by way of appending them to the URL.

curl http://instance.com/seek?question=instance
5. Ship Headers

You’ll upload headers for your request with the -H choice.

curl -H "Settle for: software/json" http://instance.com/api
6. Use Cookies

You’ll inform curl to ship cookies with the -b choice, and to retailer cookies with the -c choice.

curl -b "identify=worth" -c cookies.txt http://instance.com
7. Add Information

You’ll use curl to add information to a server with the -F choice. This sends a POST request and units the Content material-Sort to multipart/form-data.

curl -F "document=@trail/to/native/document" http://instance.com/add
8. Obtain Information

You’ll use curl to obtain information the usage of FTP, SFTP, HTTP, and plenty of different protocols.

curl -O ftp://instance.com/pub/document.zip
9. Authentication

If you want to authenticate, you’ll use the -u choice adopted by way of the username and password separated by way of a : (colon).

curl -u username:password http://instance.com
Extra Linux instructions:
Listing Operations rmdir · cd · pwd
Document Operations cat · cp · dd · much less · ls · mkdir · mv · tail · tar · zip
Document Gadget Operations chown · mkfs
Networking ping · curl · wget · iptables
Seek and Textual content Processing in finding · grep · sed · whatis
Gadget Knowledge and Control env · historical past · best · who
Person and Consultation Control display · su · sudo

The submit The right way to Use curl in Linux gave the impression first on Hongkiat.

WordPress Website Development Source: https://www.hongkiat.com/blog/linux-command-curl/

[ continue ]