{"id":14190,"date":"2022-01-21T11:55:29","date_gmt":"2022-01-21T11:55:29","guid":{"rendered":"https:\/\/linuxways.net\/?p=14190"},"modified":"2022-01-21T11:55:29","modified_gmt":"2022-01-21T11:55:29","slug":"linux-wget-command-with-examples","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/centos\/linux-wget-command-with-examples\/","title":{"rendered":"Linux wget Command with Examples"},"content":{"rendered":"<p>GNU Wget is a free tool that allows you to download files from the internet using the command-line. Wget has a lot of features, including the ability to download multiple files, limit bandwidth, resume downloads, ignore SSL checks, download in the background, mirror a website, and more.<\/p>\n<p>This article demonstrates the different options available using the wget command.<\/p>\n<h2><strong>Wget Syntax<\/strong><\/h2>\n<p>Wget takes the following simple syntax.<\/p>\n<pre><strong>$ wget [options] [url]<\/strong><\/pre>\n<h2><strong>1. Download a file<\/strong><\/h2>\n<p>With no command options, you can download a file with the wget command by specifying the URL of the resource as shown.<\/p>\n<pre><strong>$ wget https:\/\/github.com\/git\/git\/archive\/refs\/tags\/v2.34.1.zip<\/strong><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1100\" height=\"325\" class=\"wp-image-14191\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-471.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-471.png 1100w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-471-300x89.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-471-1024x303.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-471-768x227.png 768w\" sizes=\"auto, (max-width: 1100px) 100vw, 1100px\" \/><\/p>\n<h2><strong>2. Download Multiple files<\/strong><\/h2>\n<p>When it comes to downloading multiple files, you need to create a text file and list the URLs of the resources to be downloads. The text file will act as an input file from which wget will read the URLs<\/p>\n<p>In this example, we have saved a few URLs in the <strong>multipledownloads.txt<\/strong> text file<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1333\" height=\"358\" class=\"wp-image-14192\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-472.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-472.png 1333w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-472-300x81.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-472-1024x275.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-472-768x206.png 768w\" sizes=\"auto, (max-width: 1333px) 100vw, 1333px\" \/><\/p>\n<p>Next, download the files using wget with <strong>-i<\/strong>option as shown. With the<strong>-i <\/strong>option, wget reads from the input file and downloads the resources defined in the input file.<\/p>\n<pre><strong>$ wget -i multipledownloads.txt<\/strong><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1289\" height=\"181\" class=\"wp-image-14193\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-473.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-473.png 1289w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-473-300x42.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-473-1024x144.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-473-768x108.png 768w\" sizes=\"auto, (max-width: 1289px) 100vw, 1289px\" \/><\/p>\n<h2><strong>3. Download files in the background<\/strong><\/h2>\n<p>To download files in the background, use the wget command with -b option. This option comes in handy when the file is large and you need to utilize the terminal for something else.<\/p>\n<pre><strong>$ wget -b <\/strong><a href=\"https:\/\/github.com\/git\/git\/archive\/refs\/tags\/v2.33.0.zip\"><strong>https:\/\/github.com\/git\/git\/archive\/refs\/tags\/v2.34.1.zip<\/strong><\/a><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"825\" height=\"79\" class=\"wp-image-14194\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-474.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-474.png 825w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-474-300x29.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-474-768x74.png 768w\" sizes=\"auto, (max-width: 825px) 100vw, 825px\" \/><\/p>\n<p>To view the output of the download, view wget logs with the command:<\/p>\n<pre><strong>$ tail -f wget-log<\/strong><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1018\" height=\"222\" class=\"wp-image-14195\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-475.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-475.png 1018w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-475-300x65.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-475-768x167.png 768w\" sizes=\"auto, (max-width: 1018px) 100vw, 1018px\" \/><\/p>\n<h2><strong>4. Resume a download<\/strong><\/h2>\n<p>In some cases, when we start a download the internet becomes unavailable. We can use the wget command&#8217;-c&#8217; to resume our download from the point when it became unavailable. The following is an example.<\/p>\n<pre><strong>$ wget -c https:\/\/download.rockylinux.org\/pub\/rocky\/8\/isos\/x86_64\/Rocky-8.4-x86_64-minimal.iso<\/strong><\/pre>\n<h2><strong>5. Saving downloaded file under a different name.<\/strong><\/h2>\n<p>Use the wget command with the -o option followed with the desired name of the file as follows:<\/p>\n<pre><strong>$ wget -o git.zip <\/strong><a href=\"https:\/\/github.com\/git\/git\/archive\/refs\/tags\/v2.33.0.zip\"><strong>https:\/\/github.com\/git\/git\/archive\/refs\/tags\/v2.34.1.zip<\/strong><\/a><\/pre>\n<p>The file is saved as git.zip in the example above.<\/p>\n<h2><strong>6. Download file under a specific directory<\/strong><\/h2>\n<p>The wget commands save downloads in the current working directory. To specify a location use the -P option followed with path to directory.<\/p>\n<pre><strong>$ sudo wget -P \/opt\/wordpress https:\/\/wordpress.org\/latest.tar.gz<\/strong><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1103\" height=\"166\" class=\"wp-image-14196\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-476.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-476.png 1103w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-476-300x45.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-476-1024x154.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-476-768x116.png 768w\" sizes=\"auto, (max-width: 1103px) 100vw, 1103px\" \/><\/p>\n<h2><strong>7. Set the download speed<\/strong><\/h2>\n<p>By default, the wget command attempts to use all available bandwidth. However, if you are using a shared internet connection, or trying to download a large file you can use the &#8216;<strong> &#8211;limit-rate<\/strong>&#8216; option to cap the download speed to a specific value. You can set the speed in kilobytes ( k) , Megabytes ( m ) or Gigabytes ( g ).<\/p>\n<p>In this example. We have set the download speed to 100Kilobytes.<\/p>\n<pre><strong>$ wget --limit-rate=100k http:\/\/download.virtualbox.org\/virtualbox\/rpm\/rhel\/virtualbox.repo<\/strong><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1310\" height=\"240\" class=\"wp-image-14197\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-477.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-477.png 1310w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-477-300x55.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-477-1024x188.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-477-768x141.png 768w\" sizes=\"auto, (max-width: 1310px) 100vw, 1310px\" \/><\/p>\n<h2><strong>8. Mirror entire website<\/strong><\/h2>\n<p>Use the -m option with wget to create a mirror of a website. This creates a local copy of the website on your system for local browsing.<\/p>\n<pre><strong>$ wget -m https:\/\/google.com<\/strong><\/pre>\n<p>You&#8217;ll need to provide a few extra parameters to the command above if you wish to browse the downloaded page locally.<\/p>\n<pre><strong>$ wget -m -k -p https:\/\/google.com<\/strong><\/pre>\n<p>The -k option instructs wget to transform links in downloaded documents so that they can be viewed locally. The -p options provides all the<\/p>\n<p>essential files for displaying the HTML page.<\/p>\n<h2><strong>9. Ignore SSL Checks<\/strong><\/h2>\n<p>Use the <strong>\u2014no-check-certificate<\/strong> option to download a file over HTTPS from a server with an incorrect SSL certificate.<\/p>\n<pre><strong>$ wget --no-check-certificate https:\/\/website-with-invalid-ss.com<\/strong><\/pre>\n<h2><strong>10. Increase number of retries<\/strong><\/h2>\n<p>Incase of a network interruption, wget command attempt to re-establish the connection. By default, it tries 20 times to successfully complete the download. The &#8216;<strong>&#8211;tries<\/strong>&#8216; option increases the number of retry attempts.<\/p>\n<p>Here, we have set the number of retries to 75 attempts.<\/p>\n<pre><strong>$ wget --tries=75 https:\/\/download.rockylinux.org\/pub\/rocky\/8\/isos\/x86_64\/Rocky-8.4-x86_64-minimal.iso<\/strong><\/pre>\n<h2><strong>Conclusion<\/strong><\/h2>\n<p>Wget is a very useful tool for downloading files. For further information, check out the <a href=\"https:\/\/www.gnu.org\/software\/wget\/manual\/wget.html\">documentation.<\/a><\/p>","protected":false},"excerpt":{"rendered":"<p>GNU Wget is a free tool that allows you to download files from the internet using the command-line. Wget has a lot of features, including the ability to&hellip;<\/p>","protected":false},"author":1,"featured_media":14254,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,4,5,83,165,2],"tags":[35,866],"class_list":["post-14190","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-centos","category-debian","category-mint","category-opensuse","category-red-hat","category-ubuntu","tag-linux","tag-wget-command"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/14190","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=14190"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/14190\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/14254"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=14190"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=14190"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=14190"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}