Inicio·Comandos de terminal

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ónSignificado
-LFollow redirects. curl does not follow them on its own, unlike a browser.
-iPrint 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 PUTOverride the method. Unnecessary with -d, which is already a POST.
-o <file> / -OSave the body to a file / save it under the remote filename.
-s / -sSNo progress meter / silent but still print errors.
-fExit nonzero on HTTP 4xx and 5xx instead of printing the error page.
-kSkip certificate verification. Debugging only, never in production.

Ejemplos

curl -fsSL https://example.com/install.sh -o install.sh

Download quietly, follow redirects, fail loudly on a 404.

curl -i -H "Content-Type: application/json" -d '{"name":"a"}' https://api.example.com/items

POST JSON and read the response headers.

curl -s -o /dev/null -w "%{http_code}\n" https://example.com

Print 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