How to use curl and wget in Linux

· Category: Linux

Short answer

curl and wget are command-line HTTP clients. curl is versatile for APIs; wget excels at recursive downloads.

Steps

  1. Download with wget:
wget https://example.com/file.zip
  1. Download with curl:
curl -O https://example.com/file.zip
  1. POST JSON with curl:
curl -X POST -H "Content-Type: application/json" -d '{"key":"val"}' https://api.example.com
  1. Follow redirects:
curl -L https://example.com

Tips

  • curl -I fetches headers only.
  • wget -r enables recursive downloading.
  • Use -o with curl to specify an output filename.

Common issues

  • SSL errors: use -k to skip verification (insecure) or update CA certificates.
  • Large files: use -C - with curl to resume interrupted downloads.