Início·Comandos de terminal

curl

Rede

Uso

curl [options] <url>

Baixa uma URL e imprime o corpo no terminal; ao contrario de um navegador, nao segue redirecionamentos sem `-L`, entao um 301 parece uma resposta vazia.

Opções comuns

OpçãoSignificado
-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.

Exemplos

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.

Quando a conexão falha, estes mostram até onde ela chegou: o nome não resolve, não há rota ou a porta está fechada.

Como ler

  • Os colchetes [ ] marcam uma parte que você pode omitir.
  • As reticências … indicam que você pode listar vários.
  • As opções diferenciam maiúsculas: em alguns comandos -r e -R fazem coisas diferentes.

Perguntas

Q. O que curl faz?

Baixa uma URL e imprime o corpo no terminal; ao contrario de um navegador, nao segue redirecionamentos sem `-L`, entao um 301 parece uma resposta vazia.

Q. Como se digita?

curl [options] <url> — os colchetes marcam o que você pode omitir.

Q. Quantas opções vale a pena saber?

Aqui estão 9; a lista completa está em man curl. Este comando fica em Rede.

Comandos relacionados

página man: man curl