{"id":7246,"date":"2021-06-16T07:51:10","date_gmt":"2021-06-16T07:51:10","guid":{"rendered":"https:\/\/linuxways.net\/?p=7246"},"modified":"2021-06-16T07:51:10","modified_gmt":"2021-06-16T07:51:10","slug":"how-to-download-a-file-on-ubuntu-using-the-command-line","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/ubuntu\/how-to-download-a-file-on-ubuntu-using-the-command-line\/","title":{"rendered":"How to Download a File on Ubuntu Using the Command Line"},"content":{"rendered":"<p>Most of the system administrators and even some of the standard users prefer the command line for their everyday tasks like editing, and deleting files, <a href=\"https:\/\/linuxways.net\/de\/ubuntu\/how-to-add-and-remove-users-on-ubuntu-20-04\/\">creating and removing users<\/a>, <a href=\"https:\/\/linuxways.net\/de\/ubuntu\/how-to-find-your-ip-address-in-ubuntu-20-04-lts\/\">finding IP address<\/a> etc. One of the reasons for this is because the command line is faster and uses fewer resources. One other thing that users frequently do is download a file. They can also do it easily and more quickly using the command line. Wget and curl are the command line utilities that let you download files from the command line.<\/p>\n<p>In this post, we will describe how to use the wget and curl utilities to download a file on Ubuntu from the command line.<\/p>\n<p><strong>Note<\/strong>: We will be describing the procedure on <strong>Ubuntu 20.04 <\/strong>system.<\/p>\n<h2>Download Files Using Wget<\/h2>\n<p>Wget is a command-line tool used for downloading files from the web. Using wget, you can download a single HTML file or an entire website. It supports downloading of files using HTTP, HTTPS, and FTP protocols. It comes installed on almost all Linux OS. However, if you cannot find it in your system or it is mistakenly removed, you can install it as follows:<\/p>\n<pre>$ sudo apt install wget<\/pre>\n<p>The basic syntax of the wget command is as follows:<\/p>\n<pre>$ wget [option]\u2026 [URL]\u2026<\/pre>\n<h3>Download a file from command line<\/h3>\n<p>To download a file from the command line, simply type <em>wget<\/em> followed by the URL of the file you want to download. Let\u2019s say to download \u201cvnstat-2.6.tar.gz\u201d a <a href=\"https:\/\/linuxways.net\/de\/ubuntu\/monitor-network-traffic-with-vnstat-on-ubuntu-20-04\/\">network traffic monitor<\/a> package from a website, the command would be:<\/p>\n<pre>$ wget https:\/\/humdi.net\/vnstat\/vnstat-2.6.tar.gz<\/pre>\n<p>Wget will start downloading the file and you will see the progress. The file will be saved to your Terminal\u2019s current directory.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"822\" height=\"250\" class=\"wp-image-7247\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-445.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-445.png 822w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-445-300x91.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-445-768x234.png 768w\" sizes=\"auto, (max-width: 822px) 100vw, 822px\" \/><\/p>\n<h3>Resume a partially downloaded file<\/h3>\n<p>If a download is stopped due to any reason or you have manually stopped it by pressing the Ctrl+C, you can resume it using the wget command <strong>-c<\/strong> option. This option allows you to continue a partially downloaded file where you left it off.<\/p>\n<pre>$ wget -c &lt;URL&gt;<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"970\" height=\"473\" class=\"wp-image-7248\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-446.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-446.png 970w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-446-300x146.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-446-768x374.png 768w\" sizes=\"auto, (max-width: 970px) 100vw, 970px\" \/><\/p>\n<h3>Turn off verbose output<\/h3>\n<p>By default, the wget displays the verbose output showing all the details of the download process. If you want, you can limit this output using the wget <strong>-nv<\/strong> option.<\/p>\n<pre>$wget -nv &lt;URL&gt;<\/pre>\n<p>This option only displays the basic information of the download process.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1092\" height=\"111\" class=\"wp-image-7249\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-447.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-447.png 1092w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-447-300x30.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-447-1024x104.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-447-768x78.png 768w\" sizes=\"auto, (max-width: 1092px) 100vw, 1092px\" \/><\/p>\n<p>To completely turn off the verbose output, use the <strong>-q<\/strong> option:<\/p>\n<pre>$ wget -q &lt;URL&gt;<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"877\" height=\"70\" class=\"wp-image-7250\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-448.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-448.png 877w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-448-300x24.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-448-768x61.png 768w\" sizes=\"auto, (max-width: 877px) 100vw, 877px\" \/><\/p>\n<h3>Download multiple files<\/h3>\n<p>To download multiple files, type <em>wget<\/em> followed by the URLs of all the files.<\/p>\n<pre>$ wget &lt;URL1&gt; &lt;URL2&gt;<\/pre>\n<p>The wget command will download both the files and save them to your current Terminal directory.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1253\" height=\"578\" class=\"wp-image-7251\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-449.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-449.png 1253w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-449-300x138.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-449-1024x472.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-449-768x354.png 768w\" sizes=\"auto, (max-width: 1253px) 100vw, 1253px\" \/><\/p>\n<p>Another way to download multiple files is by using the wget <strong>-i<\/strong> option. Let\u2019s say you need to download a large number of files. All you need is to create a text file and list all URLs in this file (one URL per line). Then type <em>wget<\/em> followed by <strong>-i<\/strong> option and the file name containing a list of URLs:<\/p>\n<pre>$ wget -i &lt;filename&gt;<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1285\" height=\"128\" class=\"wp-image-7252\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-450.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-450.png 1285w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-450-300x30.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-450-1024x102.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-450-768x77.png 768w\" sizes=\"auto, (max-width: 1285px) 100vw, 1285px\" \/><\/p>\n<p><strong>Note<\/strong>: In the above output, we have used the <strong>-nv<\/strong> option to turn off the verbose output.<\/p>\n<h2>Download Files Using Curl<\/h2>\n<p>Curl is a command-line tool used for downloading and uploading files to or from the server. It supports over 20 protocols including FTP, HTTP, HTTPS, TFTP, IMAP, LDAP, etc<\/p>\n<p>Curl comes installed on almost all Linux OS. However, if you cannot find it in your system or it is mistakenly removed, you can install it as follows:<\/p>\n<pre>$ sudo apt install curl<\/pre>\n<p>The basic syntax of the curl command is as follows:<\/p>\n<pre>$ curl [option]\u2026 [URL]\u2026<\/pre>\n<h3>Basic curl command usage<\/h3>\n<p>The basic use of the curl command is to download a single file or a content of a webpage. Let\u2019s say to download a webpage \u201cindex.html\u201d, we would type <em>curl<\/em> followed by the URL of the webpage:<\/p>\n<pre>$ curl &lt;URL&gt;<\/pre>\n<p>This command will download the specified file in your current directory.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"807\" height=\"47\" class=\"wp-image-7253\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-451.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-451.png 807w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-451-300x17.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-451-768x45.png 768w\" sizes=\"auto, (max-width: 807px) 100vw, 807px\" \/><\/p>\n<p>After running the above curl command, you will see the HTML content displayed on the screen similar to the following: <img loading=\"lazy\" decoding=\"async\" width=\"813\" height=\"426\" class=\"wp-image-7254\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-452.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-452.png 813w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-452-300x157.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-452-768x402.png 768w\" sizes=\"auto, (max-width: 813px) 100vw, 813px\" \/><\/p>\n<h3>Save the content of the page to a file<\/h3>\n<p>You can download and save the content of a page to a file instead of displaying it on the screen. To save the file to your system, use the curl command <strong>-O <\/strong>or<strong> -o<\/strong> option. The <strong>-O<\/strong> option saves the file with the same name as the file in the remote location. While the <strong>-o<\/strong> option allows saving the file with a different name.<\/p>\n<p><strong>Using the -O option<\/strong><\/p>\n<p>With the <strong>-O<\/strong> option, you do not need to specify the file name. It will save the file in your system with the name of the file in the remote location.<\/p>\n<pre>$ curl -O &lt;URL&gt;<\/pre>\n<p>For instance, the below command will save the file with the name \u201cindex.html\u201d:<\/p>\n<pre>$ curl -O https:\/\/www.cisco.com\/c\/en\/us\/support\/switches\/index.html<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"837\" height=\"156\" class=\"wp-image-7255\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-453.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-453.png 837w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-453-300x56.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-453-768x143.png 768w\" sizes=\"auto, (max-width: 837px) 100vw, 837px\" \/><\/p>\n<p><strong>Using the -o option<\/strong><\/p>\n<p>With the <strong>-o<\/strong> option, you can specify a file name of your choice.<\/p>\n<pre>$ curl -o filename &lt;URL&gt;<\/pre>\n<p>For instance, the following command will save the file with the name \u201cswitches.html\u201d:<\/p>\n<pre>$ curl -o switches.html https:\/\/www.cisco.com\/c\/en\/us\/support\/switches\/index.html<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"976\" height=\"201\" class=\"wp-image-7256\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-454.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-454.png 976w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-454-300x62.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-454-768x158.png 768w\" sizes=\"auto, (max-width: 976px) 100vw, 976px\" \/><\/p>\n<h3>Run curl silently<\/h3>\n<p>If you do not want to view any progress bar or any error message during the curl download process, you can make it silent using the <strong>-s<\/strong> option as follows:<\/p>\n<pre>$ curl -s &lt;URL&gt;<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"864\" height=\"48\" class=\"wp-image-7257\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-455.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-455.png 864w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-455-300x17.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-455-768x43.png 768w\" sizes=\"auto, (max-width: 864px) 100vw, 864px\" \/><\/p>\n<h3>Download multiple files<\/h3>\n<p>To download multiple files, type <em>curl<\/em> followed by the URLs of all the files:<\/p>\n<pre>$ curl -O [URL1] -O [URL2] -O [URL3]\u2026.<\/pre>\n<p>This command will save all the files to your current Terminal directory.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"833\" height=\"182\" class=\"wp-image-7258\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-456.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-456.png 833w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-456-300x66.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-456-768x168.png 768w\" sizes=\"auto, (max-width: 833px) 100vw, 833px\" \/><\/p>\n<p>If there are too many URLs that you need to download, then create a text file and list the URLs in it.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"879\" height=\"90\" class=\"wp-image-7259\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-457.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-457.png 879w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-457-300x31.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-457-768x79.png 768w\" sizes=\"auto, (max-width: 879px) 100vw, 879px\" \/><\/p>\n<p>Then to download all the URLs listed in the file, use the following command:<\/p>\n<pre>$ xargs -n 1 curl -O &lt; filename<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"804\" height=\"229\" class=\"wp-image-7260\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-458.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-458.png 804w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-458-300x85.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-458-768x219.png 768w\" sizes=\"auto, (max-width: 804px) 100vw, 804px\" \/><\/p>\n<p>You can then use the <em>ls<\/em> command to confirm if all the files have been downloaded.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"858\" height=\"246\" class=\"wp-image-7261\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-459.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-459.png 858w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-459-300x86.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-459-768x220.png 768w\" sizes=\"auto, (max-width: 858px) 100vw, 858px\" \/><\/p>\n<h3>Resume a partially downloaded file<\/h3>\n<p>If a download is stopped due to any reason or you have manually stopped it by pressing the Ctrl+C, you can resume it using the curl command \u201c<strong>-C \u2013<\/strong>\u201d option. This option allows you to continue a partially downloaded file where you left it off.<\/p>\n<pre>$ curl -C - &lt;URL&gt;<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"821\" height=\"220\" class=\"wp-image-7262\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-460.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-460.png 821w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-460-300x80.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-460-768x206.png 768w\" sizes=\"auto, (max-width: 821px) 100vw, 821px\" \/><\/p>\n<p>Both wget and curl are the free and open-source command-line utilities used for the non-interactive downloading of files. Remember, although both the utilities can download files from the web; they do differ a lot in terms of functionalities. You can visit <a href=\"https:\/\/linux.die.net\/man\/1\/wget\">wget<\/a> and <a href=\"https:\/\/linux.die.net\/man\/1\/curl\">curl<\/a> man pages for a detailed overview of what these utilities are capable of.<\/p>","protected":false},"excerpt":{"rendered":"<p>Most of the system administrators and even some of the standard users prefer the command line for their everyday tasks like editing, and deleting files, creating and removing&hellip;<\/p>","protected":false},"author":1,"featured_media":7350,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[100],"class_list":["post-7246","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ubuntu","tag-ubuntu-20-04"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/7246","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=7246"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/7246\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/7350"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=7246"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=7246"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=7246"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}