wiki/cli.curl.html
2022-07-29 15:41:17 +00:00

30 lines
13 KiB
HTML

<!DOCTYPE html><html><head><meta name="viewport" content="width=device-width"/><meta charSet="utf-8"/><title>Command line: cURL</title><script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script><script id="MathJax-script" async="" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script><script type="text/x-mathjax-config">
MathJax = {
tex: {
inlineMath: [ [&#x27;$&#x27;,&#x27;$&#x27;], [&#x27;\(&#x27;,&#x27;\)&#x27;] ],
displayMath: [ [&#x27;$$&#x27;,&#x27;$$&#x27;], [&#x27;[&#x27;,&#x27;]&#x27;] ]
},
options = {
processHtmlClass = &quot;math&quot;
}
}
</script><meta name="next-head-count" content="6"/><link rel="preload" href="/wiki/_next/static/css/52fc2ba29703df73922c.css" as="style"/><link rel="stylesheet" href="/wiki/_next/static/css/52fc2ba29703df73922c.css" data-n-g=""/><noscript data-n-css=""></noscript><link rel="preload" href="/wiki/_next/static/chunks/main-ae4733327bd95c4ac325.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/webpack-50bee04d1dc61f8adf5b.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/framework.9d524150d48315f49e80.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/commons.0e1c3f9aa780c2dfe9f0.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/pages/_app-8e3d0c58a60ec788aa69.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/940643274e605e7596ecea1f2ff8d83317a3fb76.4841a16762f602a59f00.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/pages/%5B%5B...slug%5D%5D-1aa198f87ede1cd0e1dc.js" as="script"/></head><body><div id="__next"><main><h1>Command line: cURL</h1><section class="post-metadata"><span>Date: <!-- -->2021-06-04 10:56:52 +08:00</span><span>Date modified: <!-- -->2021-10-24 22:02:49 +08:00</span></section><nav class="toc"><ol class="toc-level toc-level-1"><li class="toc-item toc-item-h1"><a href="/wiki/cli.curl#synopsis" class="toc-link toc-link-h1">Synopsis</a></li><li class="toc-item toc-item-h1"><a href="/wiki/cli.curl#options" class="toc-link toc-link-h1">Options</a></li><li class="toc-item toc-item-h1"><a href="/wiki/cli.curl#examples" class="toc-link toc-link-h1">Examples</a><ol class="toc-level toc-level-2"><li class="toc-item toc-item-h2"><a href="/wiki/cli.curl#basic-usage" class="toc-link toc-link-h2">Basic usage</a></li><li class="toc-item toc-item-h2"><a href="/wiki/cli.curl#go-to-command-for-downloading-files-with-curl" class="toc-link toc-link-h2">Go-to command for downloading files with cURL</a></li></ol></li></ol></nav><p>The all-time favorite client-side networking tool for basic stuff.
It is seriously one of the best free and open-source tool out there with the plethora of protocols, leading implementation for various protocols such as HTTP3, and a lot of configurable options to fully control your request.
</p><h1 id="synopsis">Synopsis</h1><pre class="src-block"><code>curl [option...] [URL...]
</code></pre><p>cURL supports creating requests with different protocols.
Among them are HTTP, Gopher, DICT, and simple file.
To see more, you can view the cURL manual page (i.e., <code class="inline-code">man curl.1</code>) and see the protocols section.
</p><h1 id="options">Options</h1><ul><li><p><code class="inline-verbatim">-o [FILE], --output [FILE]</code> - save the results in the given file
</p></li><li><p><code class="inline-verbatim">-O, --remote-name</code> - save the results as the remote name; useful for downloading
</p></li><li><p><code class="inline-verbatim">-L, --location</code> - if there redirects, follow them; mainly used in HTTP and download links that often redirects to the real location
</p></li></ul><h1 id="examples">Examples</h1><p>This is a massive tool with a massive history so a massive list may be justified for this one.
</p><h2 id="basic-usage">Basic usage</h2><pre class="src-block"><code class="language-bash"># It will be recognized as a request to an HTTP endpoint in &#x27;gnu.org&#x27;.
curl https://gnu.org
# Save the result in a file.
curl https://foo-dogsquared.github.io --output filename
</code></pre><h2 id="go-to-command-for-downloading-files-with-curl">Go-to command for downloading files with cURL</h2><pre class="src-block"><code class="language-bash">curl -LO https://cdn.media.ccc.de/events/lac/lac18/h264-hd/lac18-24-eng-Carla_Plugin_Host_-_Feature_overview_and_workflows_hd.mp4
</code></pre><p>It can be also written like the following code block.
Useful when scripting to make it readable.
</p><pre class="src-block"><code class="language-bash">curl --location --output-name https://cdn.media.ccc.de/events/lac/lac18/h264-hd/lac18-24-eng-Carla_Plugin_Host_-_Feature_overview_and_workflows_hd.mp4
</code></pre></main></div><script id="__NEXT_DATA__" type="application/json">{"props":{"pageProps":{"metadata":{"date":"\"2021-06-04 10:56:52 +08:00\"","date_modified":"\"2021-10-24 22:02:49 +08:00\"","language":"en","source":""},"title":"Command line: cURL","hast":{"type":"root","children":[{"type":"element","tagName":"nav","properties":{"className":"toc"},"children":[{"type":"element","tagName":"ol","properties":{"className":"toc-level toc-level-1"},"children":[{"type":"element","tagName":"li","data":{"hookArgs":[{"type":"element","tagName":"h1","properties":{"id":"synopsis"},"children":[{"type":"text","value":"Synopsis"}]}]},"properties":{"className":"toc-item toc-item-h1"},"children":[{"type":"element","tagName":"a","properties":{"className":"toc-link toc-link-h1","href":"/cli.curl#synopsis"},"children":[{"type":"text","value":"Synopsis"}]}]},{"type":"element","tagName":"li","data":{"hookArgs":[{"type":"element","tagName":"h1","properties":{"id":"options"},"children":[{"type":"text","value":"Options"}]}]},"properties":{"className":"toc-item toc-item-h1"},"children":[{"type":"element","tagName":"a","properties":{"className":"toc-link toc-link-h1","href":"/cli.curl#options"},"children":[{"type":"text","value":"Options"}]}]},{"type":"element","tagName":"li","data":{"hookArgs":[{"type":"element","tagName":"h1","properties":{"id":"examples"},"children":[{"type":"text","value":"Examples"}]}]},"properties":{"className":"toc-item toc-item-h1"},"children":[{"type":"element","tagName":"a","properties":{"className":"toc-link toc-link-h1","href":"/cli.curl#examples"},"children":[{"type":"text","value":"Examples"}]},{"type":"element","tagName":"ol","properties":{"className":"toc-level toc-level-2"},"children":[{"type":"element","tagName":"li","data":{"hookArgs":[{"type":"element","tagName":"h2","properties":{"id":"basic-usage"},"children":[{"type":"text","value":"Basic usage"}]}]},"properties":{"className":"toc-item toc-item-h2"},"children":[{"type":"element","tagName":"a","properties":{"className":"toc-link toc-link-h2","href":"/cli.curl#basic-usage"},"children":[{"type":"text","value":"Basic usage"}]}]},{"type":"element","tagName":"li","data":{"hookArgs":[{"type":"element","tagName":"h2","properties":{"id":"go-to-command-for-downloading-files-with-curl"},"children":[{"type":"text","value":"Go-to command for downloading files with cURL"}]}]},"properties":{"className":"toc-item toc-item-h2"},"children":[{"type":"element","tagName":"a","properties":{"className":"toc-link toc-link-h2","href":"/cli.curl#go-to-command-for-downloading-files-with-curl"},"children":[{"type":"text","value":"Go-to command for downloading files with cURL"}]}]}]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"The all-time favorite client-side networking tool for basic stuff.\nIt is seriously one of the best free and open-source tool out there with the plethora of protocols, leading implementation for various protocols such as HTTP3, and a lot of configurable options to fully control your request.\n"}]},{"type":"element","tagName":"h1","properties":{"id":"synopsis"},"children":[{"type":"text","value":"Synopsis"}]},{"type":"element","tagName":"pre","properties":{"className":["src-block"]},"children":[{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"curl [option...] [URL...]\n"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"cURL supports creating requests with different protocols.\nAmong them are HTTP, Gopher, DICT, and simple file.\nTo see more, you can view the cURL manual page (i.e., "},{"type":"element","tagName":"code","properties":{"className":["inline-code"]},"children":[{"type":"text","value":"man curl.1"}]},{"type":"text","value":") and see the protocols section.\n"}]},{"type":"element","tagName":"h1","properties":{"id":"options"},"children":[{"type":"text","value":"Options"}]},{"type":"element","tagName":"ul","properties":{},"children":[{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"-o [FILE], --output [FILE]"}]},{"type":"text","value":" - save the results in the given file\n"}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"-O, --remote-name"}]},{"type":"text","value":" - save the results as the remote name; useful for downloading\n"}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"-L, --location"}]},{"type":"text","value":" - if there redirects, follow them; mainly used in HTTP and download links that often redirects to the real location\n"}]}]}]},{"type":"element","tagName":"h1","properties":{"id":"examples"},"children":[{"type":"text","value":"Examples"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"This is a massive tool with a massive history so a massive list may be justified for this one.\n"}]},{"type":"element","tagName":"h2","properties":{"id":"basic-usage"},"children":[{"type":"text","value":"Basic usage"}]},{"type":"element","tagName":"pre","properties":{"className":["src-block"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-bash"]},"children":[{"type":"text","value":"# It will be recognized as a request to an HTTP endpoint in 'gnu.org'.\ncurl https://gnu.org\n\n# Save the result in a file.\ncurl https://foo-dogsquared.github.io --output filename\n"}]}]},{"type":"element","tagName":"h2","properties":{"id":"go-to-command-for-downloading-files-with-curl"},"children":[{"type":"text","value":"Go-to command for downloading files with cURL"}]},{"type":"element","tagName":"pre","properties":{"className":["src-block"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-bash"]},"children":[{"type":"text","value":"curl -LO https://cdn.media.ccc.de/events/lac/lac18/h264-hd/lac18-24-eng-Carla_Plugin_Host_-_Feature_overview_and_workflows_hd.mp4\n"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"It can be also written like the following code block.\nUseful when scripting to make it readable.\n"}]},{"type":"element","tagName":"pre","properties":{"className":["src-block"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-bash"]},"children":[{"type":"text","value":"curl --location --output-name https://cdn.media.ccc.de/events/lac/lac18/h264-hd/lac18-24-eng-Carla_Plugin_Host_-_Feature_overview_and_workflows_hd.mp4\n"}]}]}]},"backlinks":[]},"__N_SSG":true},"page":"/[[...slug]]","query":{"slug":["cli.curl"]},"buildId":"Ie9t5zutrXP6Of75Cb5xF","assetPrefix":"/wiki","nextExport":false,"isFallback":false,"gsp":true}</script><script nomodule="" src="/wiki/_next/static/chunks/polyfills-99d808df29361cf7ffb1.js"></script><script src="/wiki/_next/static/chunks/main-ae4733327bd95c4ac325.js" async=""></script><script src="/wiki/_next/static/chunks/webpack-50bee04d1dc61f8adf5b.js" async=""></script><script src="/wiki/_next/static/chunks/framework.9d524150d48315f49e80.js" async=""></script><script src="/wiki/_next/static/chunks/commons.0e1c3f9aa780c2dfe9f0.js" async=""></script><script src="/wiki/_next/static/chunks/pages/_app-8e3d0c58a60ec788aa69.js" async=""></script><script src="/wiki/_next/static/chunks/940643274e605e7596ecea1f2ff8d83317a3fb76.4841a16762f602a59f00.js" async=""></script><script src="/wiki/_next/static/chunks/pages/%5B%5B...slug%5D%5D-1aa198f87ede1cd0e1dc.js" async=""></script><script src="/wiki/_next/static/Ie9t5zutrXP6Of75Cb5xF/_buildManifest.js" async=""></script><script src="/wiki/_next/static/Ie9t5zutrXP6Of75Cb5xF/_ssgManifest.js" async=""></script></body></html>