curl: Transfer data or interact with servers using various protocols
August 9th, 2024 11:28 AM Mr. Q Categories: Command
Command: curl
Used to transfer data or interact with servers using various protocols, including HTTP, HTTPS, FTP, and more. curl
is highly versatile for sending and receiving data from a server.
Sample Command and Output:
$ curl http://example.com
<!doctype html>
<html>
<head>
<title>Example Domain</title>
</head>
<body>
<p>This domain is for use in illustrative examples in documents.</p>
</body>
</html>
Description:
curl http://example.com
: Fetches and displays the content ofhttp://example.com
. The command outputs the HTML content of the webpage.
Sample Command and Output:
$ curl -o file.txt http://example.com/file.txt
Description:
curl -o file.txt http://example.com/file.txt
: Downloads the file fromhttp://example.com/file.txt
and saves it asfile.txt
in the current directory. The-o
option specifies the output file name.
Sample Command and Output:
$ curl -I http://example.com
HTTP/1.1 200 OK
Date: Fri, 09 Aug 2024 12:38:00 GMT
Server: Apache/2.4.41 (Ubuntu)
...
Description:
curl -I http://example.com
: Fetches and displays only the HTTP headers of the response fromhttp://example.com
. The-I
option retrieves header information only.
Sample Command and Output:
$ curl -d "param1=value1¶m2=value2" http://example.com/submit
Description:
curl -d "param1=value1¶m2=value2" http://example.com/submit
: Sends a POST request with form data tohttp://example.com/submit
. The-d
option is used to include data in the POST request body.
Sample Command and Output:
$ curl -u user:password http://example.com/protected
Description:
curl -u user:password http://example.com/protected
: Performs an HTTP request with basic authentication using the provided username and password. The-u
option specifies the credentials.
Additional Arguments:
- -L: Follows redirects if the requested URL has been moved to another location.
- -s: Operates in silent mode, suppressing progress and error messages.
Sample Command and Output:
$ curl -L -s http://example.com/redirect
Description:
curl -L -s http://example.com/redirect
: Follows any redirects fromhttp://example.com/redirect
and operates in silent mode, suppressing the usual output.