
Curl is a powerful command-line utility and underlying library (libcurl) used to transfer data across a wide range of network protocols, including HTTP, HTTPS, FTP, FTPS, SCP, SFTP, LDAP, MQTT, and more. It supports features like proxy support, user authentication, cookies, file uploads, and SSL connections, making it a go-to tool for developers, system administrators, and anyone working with web APIs or networked services.
This article walks you through using curl to perform a variety of HTTP requests from your terminal. You’ll learn how to download files, set custom headers, work with different HTTP methods, handle redirects, send JSON payloads, authenticate with servers, and troubleshoot using verbose mode. Whether you're testing APIs or automating network operations, curl is a powerful tool to have in your workflow.
If you just want a quick reference for common curl commands, here’s a compact list of essentials:
This section expands on the quick reference above and explains basic curl operations in more detail, including file downloads, protocol handling, and request formatting. These commands are commonly used for testing connectivity or fetching public web content.
The basic syntax of the curl command is:
curl Command OptionsThe following sections explain how each curl command works in more detail. You'll find examples, syntax breakdowns, and usage notes to help you understand what each option does and when to use it. These walkthroughs complement the quick reference section above for users who prefer step-by-step explanations.
To download a webpage and print its source code to the terminal.
To retrieve a file using FTP.
Save the downloaded output to a local file instead of printing it to the terminal.
-o: Save output with a custom filename.-O: Save output using the remote filename.If a download was interrupted (e.g., due to network issues), use this option to resume it from where it left off instead of restarting from scratch.
-C -: Resume download.-O: Save using remote file name.Enable verbose output to debug request/response communication.
-v: Verbose mode.Curl provides a wide range of options to interact with web services. This section covers how to inspect headers, follow redirects, change HTTP methods, and customize request headers.
Fetch only the response headers of a URL.
-I or --head: Fetch headers only.Enable following of HTTP 3xx redirects.
-L: Follow redirects.Set a custom HTTP method using -X.
-X: Specify HTTP method (e.g., GET, POST, DELETE).Use the -H flag to add one or more HTTP headers.
Use --user-agent to define the request’s User-Agent string.
Use curl to send form-encoded or JSON data in HTTP POST requests. This is essential for interacting with REST APIs or submitting data to a server.
When accessing resources protected by HTTP Basic Auth, use the -u option to include your credentials directly in the request.
This section covers advanced curl patterns commonly used in scripts, automation, and API integrations.
Curl is an essential tool for developers and system administrators who need to interact with web servers, APIs, and remote resources from the command line. This article covered both quick-use examples and detailed explanations for common curl operations such as downloading files, handling headers, sending data, and authenticating requests.
For further exploration, refer to the official curl documentation or man page to discover protocol-specific features, scripting tricks, and advanced usage patterns.
0 Comments
Be the first to comment and share your perspective with the community.