curl
Red
Uso
curl [options] <url>Descarga una URL e imprime el cuerpo en la terminal; a diferencia de un navegador, no sigue redirecciones sin `-L`, asi que un 301 parece una respuesta vacia.
Opciones habituales
| Opción | Significado |
|---|---|
| -L | Follow redirects. curl does not follow them on its own, unlike a browser. |
| -i | Print the response headers along with the body; -I sends HEAD and prints headers only. |
| -d '{"a":1}' | Send a request body. This alone already means POST. |
| -H "Content-Type: application/json" | Add a request header; repeat -H for more. |
| -X PUT | Override the method. Unnecessary with -d, which is already a POST. |
| -o <file> / -O | Save the body to a file / save it under the remote filename. |
| -s / -sS | No progress meter / silent but still print errors. |
| -f | Exit nonzero on HTTP 4xx and 5xx instead of printing the error page. |
| -k | Skip certificate verification. Debugging only, never in production. |
Ejemplos
curl -fsSL https://example.com/install.sh -o install.shDownload quietly, follow redirects, fail loudly on a 404.
curl -i -H "Content-Type: application/json" -d '{"name":"a"}' https://api.example.com/itemsPOST JSON and read the response headers.
curl -s -o /dev/null -w "%{http_code}\n" https://example.comPrint just the status code.
Cuando falla una conexión, estos acotan hasta dónde llegó: el nombre no resuelve, no hay ruta o el puerto está cerrado.
Cómo leerlo
- Los corchetes [ ] marcan una parte que puedes omitir.
- Los puntos suspensivos … indican que puedes poner varios.
- Las opciones distinguen mayúsculas: en algunos comandos -r y -R no hacen lo mismo.
Preguntas
Q. ¿Qué hace curl?
Descarga una URL e imprime el cuerpo en la terminal; a diferencia de un navegador, no sigue redirecciones sin `-L`, asi que un 301 parece una respuesta vacia.
Q. ¿Cómo se escribe?
curl [options] <url> — los corchetes marcan lo que puedes omitir.
Q. ¿Cuántas opciones vale la pena saber?
Aquí van 9; la lista completa está en man curl. Este comando está en Red.
Comandos relacionados
página man: man curl