Linux Comm Curl
[ Linux Command Reference](#)\n\n* * *\n\n## What is the curl Command\n\ncurl (Client URL) is a powerful command-line tool for transferring data in Linux/Unix systems. It supports multiple protocols including HTTP, HTTPS, FTP, SFTP, and more, making it an indispensable tool for developers and system administrators in their daily work.\n\n### Main Features of curl\n\n1. **Multi-protocol Support**: Supports almost all mainstream network protocols\n2. **No GUI Operation**: Pure command-line tool, suitable for scripts and automation tasks\n3. **Rich Functionality**: Supports file upload/download, form submission, cookie handling, etc.\n4. **Cross-platform**: Available on Linux, macOS, and Windows\n\n* * *\n\n## Basic Syntax Structure\n\nThe basic syntax format of the curl command is as follows:\n\ncurl [URL...]\n### Parameter Description\n\n* `options`: Various optional parameters to control curl's behavior\n* `URL`: One or more web addresses to access\n\n* * *\n\n## Detailed Explanation of Common Options\n\n### 1. Basic Request Control\n\n| Option | Description | Example |\n| --- | --- | --- |\n| `-X` | Specify HTTP method | `curl -X POST https://example.com` |\n| `-d` | Send POST data | `curl -d "name=John" https://example.com` |\n| `-G` | Send -d data as GET parameters | `curl -G -d "q=keyword" https://search.com` |\n| `-H` | Add request header | `curl -H "Content-Type: application/json" https://api.com` |\n\n### 2. Output Control\n\n| Option | Description | Example |\n| --- | --- | --- |\n| `-o` | Save output to file | `curl -o output.html https://example.com` |\n| `-O` | Save with remote filename | `curl -O https://example.com/file.zip` |\n| `-s` | Silent mode (no progress display) | `curl -s https://api.com/data.json` |\n| `-v` | Show detailed communication process | `curl -v https://example.com` |\n\n### 3. Authentication and Security\n\n| Option | Description | Example |\n| --- | --- | --- |\n| `-u` | Username and password authentication | `curl -u user:pass https://secure.com` |\n| `-k` | Ignore SSL certificate verification | `curl -k https://self-signed.com` |\n| `--cacert` | Specify CA certificate | `curl --cacert cert.pem https://secure.com` |\n\n### 4. Other Practical Options\n\n| Option | Description | Example |\n| --- | --- | --- |\n| `-L` | Follow redirects | `curl -L https://short.url` |\n| `-I` | Get header information only | `curl -I https://example.com` |\n| `--limit-rate` | Limit transfer speed | `curl --limit-rate 100K https://largefile.com` |\n\n* * *\n\n## Practical Examples\n\n### Example 1: Get Web Page Content\n\n## Examples\n\ncurl https://www.example.com\n\nThis simplest command retrieves the content of the specified URL and displays it in the terminal.\n\n### Example 2: Download File\n\n## Examples\n\ncurl -O https://example.com/files/document.pdf\n\nThe `-O` option saves the file locally using the remote filename (document.pdf).\n\n### Example 3: Send POST Request\n\n## Examples\n\ncurl -X POST -d"username=admin&password=123456" https://api.example.com/login\n\nThis command sends username and password to the login interface.\n\n### Example 4: POST Request with JSON Data\n\n## Examples\n\ncurl -X POST -H"Content-Type: application/json" \n\n-d'{"name":"John","age":30}' \n\n https://api.example.com/users\n\n### Example 5: Use Cookie to Maintain Session\n\n## Examples\n\ncurl -c cookies.txt -b cookies.txt https://member.example.com\n\n* `-c` saves cookies returned by the server\n* `-b` sends stored cookies\n\n* * *\n\n## Advanced Usage\n\n### 1. File Upload\n\n## Examples\n\ncurl -F"file=@localfile.txt" https://upload.example.com\n\n`-F` is used for multipart/form-data type form submission, commonly used for file uploads.\n\n### 2. Test Website Response Time\n\n## Examples\n\ncurl -o/dev/null -s-w"Connect: %{time_connect} TTFB: %{time_starttransfer} Total: %{time_total}n" https://example.com\n\nThis command outputs:\n\n* Connection time\n* Time to First Byte (TTFB)\n* Total time\n\n### 3. Use Proxy Server\n\n## Examples\n\ncurl -x http://proxy.example.com:8080 https://target.com\n\nThe `-x` option specifies the proxy server address and port.\n\n* * *\n\n## FAQ\n\n### Q1: How to resolve curl certificate verification errors?\n\nWhen encountering SSL certificate errors, you can temporarily use the `-k` option to ignore verification (not recommended for production environments), or properly configure the CA certificate:\n\n## Examples\n\ncurl --cacert/path/to/cert.pem https://secure-site.com\n\n### Q2: How to display request and response headers?\n\nUse the `-v` or `-i` options:\n\n## Examples\n\ncurl -v https://example.com # Show detailed communication process\n\n curl -i https://example.com # Show response headers only\n\n### Q3: How to limit download speed?\n\nUse the `--limit-rate` option (units can be K, M):\n\n## Examples\n\ncurl --limit-rate 200K -O https://example.com/largefile.iso\n\n* * *\n\n## Practice Exercises\n\n1. Try downloading data from a public JSON API and save it to a file\n2. Use curl to test the response time of your local development server\n3. Practice sending a GET request with an authentication header\n4. Try uploading a test file to a free HTTP bin service\n\n## Examples\n\n# Practice examples\n\n curl https://httpbin.org/get\n\n curl -o test.json https://api.github.com/users/octocat\n\n curl -X POST -F"file=@test.txt" https://httpbin.org/post\n\n* * *\n\n## Summary\n\ncurl is a powerful network data transfer tool in Linux systems. Through this tutorial, you should have mastered:\n\n1. Basic syntax and common options of curl\n2. Usage examples for various common scenarios\n3. Advanced features and practical tips\n4. Solutions to common problems\n\nTo learn more details, you can check curl's official documentation or use `man curl` to view the manual page. As you gain practical experience, you'll find that curl can accomplish far more than these basic functions.\n\n[ Linux Command Reference](#)
YouTip