{"id":15606,"date":"2019-02-21T15:03:26","date_gmt":"2019-02-21T15:03:26","guid":{"rendered":"https:\/\/www.hostinger.com\/tutorials\/?p=15606"},"modified":"2025-12-22T12:38:26","modified_gmt":"2025-12-22T12:38:26","slug":"curl-command","status":"publish","type":"post","link":"\/tutorials\/curl-command","title":{"rendered":"What is the cURL command? understanding the syntax, options, and examples"},"content":{"rendered":"<p>The curl command (client URL) is a command-line tool for transferring data to or from a server. At its simplest, you specify a URL and the data to send or receive. It supports many protocols, including HTTP, HTTPS, and FTP, and runs on most operating systems.<\/p><p>The cURL command in Linux enables your system to exchange data with servers via the internet. This tool is essential for various tasks, including downloading files and checking API functionality.<\/p><p>In this tutorial, we will explain the cURL command, including its installation and syntax. You will also learn several cURL command examples for practical usage.<\/p><h2 class=\"wp-block-heading\" id=\"h-what-is-the-curl-command\">What is the cURL command?<\/h2><p>The cURL command (client URL) is a powerful tool used for transferring data to and from servers. It operates through the command-line interface (CLI) and supports various protocols like HTTP, HTTPS, FTP, and SMTP. This flexibility makes it highly effective for tasks like <strong>API testing<\/strong>, downloading files, and interacting with web servers directly.<\/p><p>While alternatives like Postman offer a graphical user interface (GUI) for these tasks, cURL remains a favorite for developers due to its simplicity, speed, and compatibility with a wide range of protocols. For those who use <a href=\"\/tutorials\/linux-commands\">Linux commands<\/a> regularly, cURL is an indispensable tool.<\/p><h2 class=\"wp-block-heading\" id=\"h-installing-curl\">Installing cURL<\/h2><p>The cURL command should come pre-installed by default on most Linux operating systems. To check whether it is configured, open Terminal or <a href=\"\/tutorials\/linux-commands\">connect via SSH<\/a> if you use a remote virtual private server (VPS) platform.&nbsp;<\/p><p>For <a href=\"\/vps-hosting\">Hostinger VPS<\/a> users, you can also connect to your system with one click using <strong>Browser terminal<\/strong>. Simply open your VPS management page on hPanel and hit the button at the top right.&nbsp;<\/p><figure class=\"wp-block-image size-large\"><a class=\"hgr-tutorials-cta hgr-tutorials-cta-vps-hosting\" href=\"\/vps-hosting\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" width=\"1024\" height=\"300\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/02\/VPS-hosting-banner.png\/public\" alt=\"\" class=\"wp-image-77934\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/02\/VPS-hosting-banner.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/02\/VPS-hosting-banner.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/02\/VPS-hosting-banner.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/02\/VPS-hosting-banner.png\/w=768,fit=scale-down 768w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><p>After accessing your system&rsquo;s CLI, run the following to check if cURL is installed:<\/p><pre class=\"wp-block-preformatted\">curl --version<\/pre><p>If your system has cURL, the CLI will return the installed version number. Otherwise, you will get the <strong>Command not found <\/strong>error.<\/p><div class=\"wp-block-image\">\n<figure data-wp-context='{\"imageId\":\"69e9015bdc410\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-full wp-lightbox-container\"><img decoding=\"async\" width=\"576\" height=\"74\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/02\/terminal-outputs-curl-version.png\/public\" alt=\"Terminal outputs cURL version\" class=\"wp-image-119859\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/02\/terminal-outputs-curl-version.png\/w=576,fit=scale-down 576w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/02\/terminal-outputs-curl-version.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/02\/terminal-outputs-curl-version.png\/w=150,fit=scale-down 150w\" sizes=\"(max-width: 576px) 100vw, 576px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><p>To install it, run the following commands subsequently. Remember to replace <strong>apt <\/strong>with the correct package manager based on your Linux operating system:<\/p><pre class=\"wp-block-preformatted\">sudo apt update &amp;&amp; sudo apt upgrade<\/pre><pre class=\"wp-block-preformatted\">sudo apt install curl<\/pre><h2 class=\"wp-block-heading\" id=\"h-curl-command-basic-syntax-and-options\">cURL command basic syntax and options<\/h2><p>The cURL command basic syntax looks as follows:<\/p><pre class=\"wp-block-preformatted\">curl [options] [URL]<\/pre><p>Here is the breakdown of the syntax:<\/p><ul class=\"wp-block-list\">\n<li><strong>cURL <\/strong>&ndash; the command name telling your system that you are running cURL.<\/li>\n\n\n\n<li><strong>Options <\/strong>&ndash; additional flags modifying the cURL command behavior.<\/li>\n\n\n\n<li><strong>URL <\/strong>&ndash; the address of the destination server or endpoint.&nbsp;<\/li>\n<\/ul><p>Since there are various options, check the <a href=\"https:\/\/curl.se\/docs\/optionsall.html\" target=\"_blank\" rel=\"noopener\">cURL documentation<\/a> for the full list. Among them, here are some of the most used ones:<\/p><ul class=\"wp-block-list\">\n<li><strong>&ndash;help <\/strong>&ndash; prints the cURL command manual and options.&nbsp;<\/li>\n\n\n\n<li><strong>-O <\/strong>&ndash; downloads the original file from the given URL.&nbsp;<\/li>\n\n\n\n<li><strong>-L<\/strong> &ndash; follows the redirection URLs.<\/li>\n\n\n\n<li><strong>-I<\/strong> &ndash; fetches only the header.<\/li>\n\n\n\n<li><strong>-d<\/strong> &ndash; submits form data.&nbsp;<\/li>\n\n\n\n<li><strong>-F<\/strong> &ndash; uploads complex data or files.&nbsp;<\/li>\n\n\n\n<li><strong>-X<\/strong> &ndash; specifies the method for transferring data.&nbsp;<\/li>\n<\/ul><p>\n\n\n\n<div><p class=\"important\">Linux commands are case-sensitive. Make sure to use the options with the correct capitalization to avoid errors.<\/p><\/div>\n\n\n\n<\/p><p>The cURL command lets you send or fetch data from an endpoint using different HTTP methods:<\/p><ul class=\"wp-block-list\">\n<li><strong>GET<\/strong> &ndash; the default method that fetches data from the server.&nbsp;<\/li>\n\n\n\n<li><strong>POST <\/strong>&ndash; sends data to the endpoint.&nbsp;<\/li>\n\n\n\n<li><strong>PUT <\/strong>&ndash; creates a resource on the endpoint or updates an existing one.<\/li>\n\n\n\n<li><strong>DELETE<\/strong> &ndash; removes data from the endpoint.<\/li>\n<\/ul><h2 class=\"wp-block-heading\" id=\"h-curl-command-examples\">cURL command examples<\/h2><p>In this section, we will explore several real-world examples of the cURL command for various tasks.<\/p><h3 class=\"wp-block-heading\" id=\"h-getting-a-web-page\">Getting a web page<\/h3><p>The most basic usage of the cURL command is to fetch the HTML content of a web page. To do so, simply run cURL with the destination endpoint like so:<\/p><pre class=\"wp-block-preformatted\">curl https:\/\/www.google.com<\/pre><p>The cURL command will output the web page&rsquo;s HTML code as a standard output in your CLI.<\/p><div class=\"wp-block-image\">\n<figure data-wp-context='{\"imageId\":\"69e9015bdfb70\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-large wp-lightbox-container\"><img decoding=\"async\" width=\"1460\" height=\"112\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/02\/curl-fetches-a-web-page-html-content.png\/public\" alt=\"cURL fetches a web page's HTML content\" class=\"wp-image-119860\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/02\/curl-fetches-a-web-page-html-content.png\/w=1460,fit=scale-down 1460w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/02\/curl-fetches-a-web-page-html-content.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/02\/curl-fetches-a-web-page-html-content.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/02\/curl-fetches-a-web-page-html-content.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/02\/curl-fetches-a-web-page-html-content.png\/w=768,fit=scale-down 768w\" sizes=\"(max-width: 1460px) 100vw, 1460px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><p>You can also send HTTP requests to multiple URLs using a single command like so:<\/p><pre class=\"wp-block-preformatted\">curl https:\/\/www.example1.com https:\/\/example2.com<\/pre><h3 class=\"wp-block-heading\" id=\"h-saving-output-to-a-file\">Saving output to a file<\/h3><p>You can save the cURL command&rsquo;s output to a file by appending it with a redirection operation (<strong>&gt;<\/strong>). This is helpful if you want to store the result for monitoring or archive.<\/p><p>For example, the following will store Google&rsquo;s HTML content to <strong>file1.txt<\/strong>:<\/p><pre class=\"wp-block-preformatted\">curl https:\/\/www.google.com &gt; file1.txt<\/pre><p>The command will create the file automatically if you don&rsquo;t have one. Meanwhile, if<strong> file1.txt <\/strong>already exists, cURL will overwrite the existing file.<\/p><h3 class=\"wp-block-heading\" id=\"h-downloading-a-file-with-its-original-name\">Downloading a file with its original name<\/h3><p>One of cURL&rsquo;s most common uses is downloading a remote file from the internet, similar to <a href=\"\/tutorials\/wget-command-examples\/\">wget<\/a>. To do so, use the<strong> -O<\/strong> option like:<\/p><pre class=\"wp-block-preformatted\">curl -O http:\/\/www.example.com\/path\/file.zip<\/pre><p>The command will download the specified file called <strong>file.zip<\/strong> to your current working directory. Without the <strong>-O <\/strong>option, cURL will display the file&rsquo;s content as a standard output on your CLI.<\/p><h3 class=\"wp-block-heading\" id=\"h-following-redirects\">Following redirects<\/h3><p>If a URL redirects to another page, cURL won&rsquo;t follow it and will return the <strong>301 <\/strong>or <strong>302 <\/strong>status. For example, let&rsquo;s check <strong>googlr.com<\/strong>:<\/p><pre class=\"wp-block-preformatted\">curl http:\/\/www.googlr.com<\/pre><p>Since this URL redirects to <strong>google.com<\/strong>, cURL can&rsquo;t follow it and return the <strong>301 <\/strong>status indicating the document has moved.<\/p><div class=\"wp-block-image\">\n<figure data-wp-context='{\"imageId\":\"69e9015be2ac9\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-large wp-lightbox-container\"><img decoding=\"async\" width=\"1460\" height=\"253\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/02\/curl-returns-301-redirect-status.png\/public\" alt=\"cURL returns the 301 redirect status\" class=\"wp-image-119861\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/02\/curl-returns-301-redirect-status.png\/w=1460,fit=scale-down 1460w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/02\/curl-returns-301-redirect-status.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/02\/curl-returns-301-redirect-status.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/02\/curl-returns-301-redirect-status.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2019\/02\/curl-returns-301-redirect-status.png\/w=768,fit=scale-down 768w\" sizes=\"(max-width: 1460px) 100vw, 1460px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><p>To automatically follow the redirect and output <strong>google.com<\/strong>&rsquo;s content, add the <strong>-L<\/strong> or<strong> &ndash;location <\/strong>option like so:<\/p><pre class=\"wp-block-preformatted\">curl -L http:\/\/www.googlr.com<\/pre><p>If the URL redirects multiple times, you can limit how many times cURL will follow it using the <strong>&ndash;max-redirs <\/strong>option like so:<\/p><pre class=\"wp-block-preformatted\">curl -L --max-redirs 3 http:\/\/www.googlr.com<\/pre><h3 class=\"wp-block-heading\" id=\"h-fetching-only-headers\">Fetching only headers<\/h3><p>In some cases, fetching the endpoint&rsquo;s response <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/HTTP\/Headers\" target=\"_blank\" rel=\"noopener\">header<\/a> is more helpful than retrieving the entire content. It shortens the output for simpler analysis and minimizes bandwidth consumption.<\/p><p>Information in response headers are generally sufficient for testing purposes. For example, it contains the HTTP response status, the remaining API calls, and redirects.<\/p><p>To fetch only the headers using cURL, add the <strong>-I <\/strong>(uppercase<strong> i<\/strong>) or <strong>&ndash;head <\/strong>option like so:<\/p><pre class=\"wp-block-preformatted\">curl -I http:\/\/www.google.com<\/pre><h3 class=\"wp-block-heading\" id=\"h-authenticated-requests\">Authenticated requests<\/h3><p>When sending a request to a secured endpoint like an internal API, typically you need to authenticate it by including the credentials in your cURL command.<\/p><p>Depending on the authentication method, however, the command and option differ. For example, run the following if you use a typical username and password:<\/p><pre class=\"wp-block-preformatted\">curl -u username:password &lt;URL&gt;<\/pre><p>You can also omit <strong>:password <\/strong>and enter it separately later to prevent the credential from showing on the bash history.<\/p><p>If you use the Bearer token, use the following command syntax:<\/p><pre class=\"wp-block-preformatted\">curl -H \"Authorization: Bearer &lt;token&gt;\" &lt;URL&gt;<\/pre><p>The command is similar if you use an API key in the header for authentication:<\/p><pre class=\"wp-block-preformatted\">curl -H \"Authorization: ApiKey &lt;API key&gt;\" &lt;URL&gt;<\/pre><p>If your API specifically needs the authorization key directly in the URL, you can add it using the following command:<\/p><pre class=\"wp-block-preformatted\">curl \"https:\/\/api.example.com\/data?api_key=api_key\"<\/pre><h3 class=\"wp-block-heading\" id=\"h-submitting-form-data\">Submitting form data<\/h3><p>cURL lets you easily submit data to forms on an endpoint. This is useful if you want to automate the process using bash script or when you don&rsquo;t want to interact with the destination&rsquo;s web interface.&nbsp;<\/p><p>Form submission using cURL requires you to specify the <strong>key-value<\/strong> pair. The <strong>key<\/strong> refers to the form name, while the <strong>value<\/strong> indicates the data you want to insert. The syntax looks like this:<\/p><pre class=\"wp-block-preformatted\">key1=value1&amp;key2=value2<\/pre><p>You need two options, <strong>-X <\/strong>to specify the submission method and <strong>-d<\/strong> to indicate cURL that you want to insert data. The full command might look like this:<\/p><pre class=\"wp-block-preformatted\">curl -X POST -d \"username=johndoe&amp;password=secret\" https:\/\/example.com\/login<\/pre><p>In the example, cURL uses the POST request to enter the credentials into the login page&rsquo;s form.<\/p><p>When submitting form data, ensure it follows the <a href=\"https:\/\/www.w3schools.com\/tags\/ref_urlencode.ASP\" target=\"_blank\" rel=\"noopener\">URL naming format<\/a>. For example, replace a <strong>space<\/strong> with <strong>%20<\/strong> and an ampersand (<strong>&amp;<\/strong>) with <strong>%26<\/strong>.<\/p><p>You can also insert data from a file using the following syntax. Make sure the file contains the data in the proper key-value pair format.<\/p><pre class=\"wp-block-preformatted\">curl -X POST -d @data.txt https:\/\/example.com\/login<\/pre><h3 class=\"wp-block-heading\" id=\"h-uploading-a-file\">Uploading a file<\/h3><p>If you want to submit a local file or more complex data to an endpoint, use the<strong> -F <\/strong>option. This flag also assumes you use the POST method by default, so you don&rsquo;t need to specify it manually with <strong>-X<\/strong>.<\/p><p>For example, the following sends a text file to the endpoint:<\/p><pre class=\"wp-block-preformatted\">curl -F \"file=@test.txt\" https:\/\/example.com\/upload<\/pre><p>If you want to send multiple files, simply list them in your command, each starting with the <strong>-F <\/strong>option like so:<\/p><pre class=\"wp-block-preformatted\">curl -F \"file=@\/path\/to\/image.jpg\" -F \"file=@\/path\/to\/image2.jpg\" https:\/\/example.com\/upload<\/pre><p>You can also upload files using cURL via the <a href=\"\/tutorials\/what-is-ftp\">file transfer protocol<\/a> (FTP). The difference is that you use the <strong>&nbsp;-T <\/strong>option like so:<\/p><pre class=\"wp-block-preformatted\">curl -T \/path\/to\/file ftp:\/\/ftp.example.com\/remote\/path\/<\/pre><p>For a secure file transfer protocol (SFTP) or protected FTP server, add the authentication credentials before the <strong>-T<\/strong> option like so:<\/p><pre class=\"wp-block-preformatted\">curl -u username:password -T \/path\/to\/file sftp:\/\/sftp.example.com\/remote\/path\/<\/pre><h3 class=\"wp-block-heading\" id=\"h-setting-custom-headers\">Setting custom headers<\/h3><p>Using custom request headers lets you interact with the web server or API in a specific way. It enables you to add specific metadata for a personalized response, which is useful when testing the endpoint&rsquo;s functionality.<\/p><p>You can set a custom header with the <strong>-H <\/strong>option using this syntax:<\/p><pre class=\"wp-block-preformatted\">&#8203;&#8203;curl -H \"Header: value\" &lt;URL&gt;<\/pre><p>For example, you can specify the type of content you want to send in the header. Here&rsquo;s the command:<\/p><pre class=\"wp-block-preformatted\">curl -X POST -H \"Content-Type: application\/json\" -d '{\"form\":\"JSONdata\"}' https:\/\/api.example.com\/<\/pre><p>You can also set a custom header to define the type of content you accept as a response. For example, if you want the endpoint to respond with JSON, use the following:<\/p><pre class=\"wp-block-preformatted\">curl -H \"Accept: application\/json\" https:\/\/api.example.com\/data<\/pre><p>When testing API, you can set a custom header to specify the version to use. The command looks like this:<\/p><pre class=\"wp-block-preformatted\">curl -H \"X-API-Version: 2\" https:\/\/api.example.com\/v2\/data<\/pre><h3 class=\"wp-block-heading\" id=\"h-using-different-protocols\">Using different protocols<\/h3><p>Depending on the endpoint, you might need to use different protocols with cURL. For example, you might want to use SFTP to transfer files while testing a mailing server requires SMTP.<\/p><p>To run cURL using different protocols, simply specify it at the beginning of your endpoint&rsquo;s URL before <strong>:\/\/<\/strong>. For example, this command will transfer data using SMTP:<\/p><pre class=\"wp-block-preformatted\">curl --url smtp:\/\/smtp.example.com --mail-from \"user@example.com\" --mail-rcpt \"recipient@example.com\" -T email.txt<\/pre><p>The command will send a message from <strong>user@example.com<\/strong> to <strong>recipient@example.com<\/strong> via the <strong>smtp.example.com<\/strong> mailing server using the SMTP protocol.<\/p><h2 class=\"wp-block-heading\" id=\"h-conclusion\">Conclusion<\/h2><p>The cURL command in Linux lets your system connect to and transfer data with a server. It is known for its compatibility with various protocols and ability to include additional information, like a custom header.<\/p><p>While cURL is pre-installed in most Linux distributions, you can configure it manually using your package manager. The basic usage of this command is to fetch a web page&rsquo;s content or an API response.<\/p><p>You can also download files using cURL with the<strong> -O<\/strong> option or upload items by adding the<strong> -F <\/strong>flag. Moreover, use <strong>-H<\/strong> to specify a custom request header for various purposes, including adding an authentication token and specifying the API version.<\/p><p>To send form data using cURL, use the <strong>-d <\/strong>option. Meanwhile, add the<strong> -F<\/strong> flag to upload more complex resources like files.<\/p><h2 class=\"wp-block-heading\" id=\"h-curl-command-faq\">cURL command FAQ<\/h2><div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1733744591545\"><h3 class=\"schema-faq-question\">What is the cURL command used for in Linux?<\/h3> <p class=\"schema-faq-answer\">In Linux, the cURL command enables you to connect to and transfer data with a remote server. It is useful for various tasks, including downloading a file from a website and sending requests to an API for testing.&nbsp;<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1733744599452\"><h3 class=\"schema-faq-question\">What protocols does cURL support?<\/h3> <p class=\"schema-faq-answer\">What protocols does cURL support?<br>cURL supports various data transfer protocols, including HTTP, HTTPS, FTP, and SMTP.&nbsp; To use a particular protocol, simply insert it at the beginning of the URL before the <strong>:\/\/<\/strong> part. For example, add the <strong>ftp:\/\/www.example.com<\/strong> endpoint if you wish to use <strong>FTP<\/strong>.&nbsp;<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1733744607069\"><h3 class=\"schema-faq-question\">How do I check if cURL is installed on my system?<\/h3> <p class=\"schema-faq-answer\">To check if cURL is installed on your system, run the <strong>curl &ndash;version <\/strong>command. If your CLI returns a version number, cURL is installed. Otherwise, it will output the <strong>Command not found <\/strong>error.&nbsp;<\/p> <\/div> <\/div><h3 class=\"wp-block-heading\" id=\"h-\"><\/h3>\n","protected":false},"excerpt":{"rendered":"<p>The curl command (client URL) is a command-line tool for transferring data to or from a server. At its simplest, [&#8230;]<\/p>\n<p><a class=\"btn btn-secondary understrap-read-more-link\" href=\"\/tutorials\/curl-command\">Read More&#8230;<\/a><\/p>\n","protected":false},"author":337,"featured_media":117741,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_title":"Linux curl command: Syntax, options and examples","rank_math_description":"The Linux cURL command lets you transfer data with systems. Check out this article to learn more about its usage and its real-world examples.","rank_math_focus_keyword":"curl command","footnotes":""},"categories":[22648,22644],"tags":[],"class_list":["post-15606","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-managing-monitoring-and-security","category-vps"],"hreflangs":[{"locale":"en-US","link":"https:\/\/www.hostinger.com\/tutorials\/curl-command","default":0},{"locale":"fr-FR","link":"https:\/\/www.hostinger.com\/fr\/tutoriels\/comment-utiliser-la-commande-curl-sous-linux","default":0},{"locale":"es-ES","link":"https:\/\/www.hostinger.com\/es\/tutoriales\/comando-curl","default":0},{"locale":"id-ID","link":"https:\/\/www.hostinger.com\/id\/tutorial\/apa-itu-curl","default":0},{"locale":"nl-NL","link":"https:\/\/www.hostinger.com\/nl\/tutorials\/wat-is-een-curl","default":0},{"locale":"en-UK","link":"https:\/\/www.hostinger.com\/uk\/tutorials\/curl-command","default":0},{"locale":"en-MY","link":"https:\/\/www.hostinger.com\/my\/tutorials\/curl-command","default":0},{"locale":"en-PH","link":"https:\/\/www.hostinger.com\/ph\/tutorials\/curl-command","default":0},{"locale":"es-MX","link":"https:\/\/www.hostinger.com\/mx\/tutoriales\/comando-curl","default":0},{"locale":"es-CO","link":"https:\/\/www.hostinger.com\/co\/tutoriales\/comando-curl","default":0},{"locale":"es-AR","link":"https:\/\/www.hostinger.com\/ar\/tutoriales\/comando-curl","default":0},{"locale":"en-IN","link":"https:\/\/www.hostinger.com\/in\/tutorials\/curl-command","default":0},{"locale":"en-CA","link":"https:\/\/www.hostinger.com\/ca\/tutorials\/curl-command","default":0},{"locale":"en-AU","link":"https:\/\/www.hostinger.com\/au\/tutorials\/curl-command","default":0},{"locale":"en-NG","link":"https:\/\/www.hostinger.com\/ng\/tutorials\/curl-command","default":0}],"_links":{"self":[{"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/posts\/15606","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/users\/337"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/comments?post=15606"}],"version-history":[{"count":39,"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/posts\/15606\/revisions"}],"predecessor-version":[{"id":138084,"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/posts\/15606\/revisions\/138084"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/media\/117741"}],"wp:attachment":[{"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/media?parent=15606"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/categories?post=15606"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/tags?post=15606"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}