{"id":151,"date":"2017-04-06T11:01:28","date_gmt":"2017-04-06T14:01:28","guid":{"rendered":"https:\/\/www.linuxpro.com.br\/2017\/04\/usando-comando-wget-no-linux\/"},"modified":"2026-09-08T02:28:46","modified_gmt":"2026-09-08T05:28:46","slug":"usando-comando-wget-no-linux","status":"publish","type":"post","link":"https:\/\/www.linuxpro.com.br\/en\/2017\/04\/usando-comando-wget-no-linux\/","title":{"rendered":"Using the wget command on Linux"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" alt=\"Mascote do LinuxPro com as m\u00e3os no teclado e no mouse, acompanhando um download em progresso no terminal, com pacotes descendo da nuvem\" src=\"\/wp-content\/uploads\/2026\/09\/wget-v3.webp\" width=\"1052\" height=\"652\" \/><\/p>\n<div style=\"background:#fff8e1;border-left:4px solid #8b1a1a;padding:.8em 1em;margin:1em 0\"><strong>Note (2026):<\/strong> revised 2017 post. The examples have been rebuilt (the Ubuntu 16.04 link no longer exists), and I added what the original text lacked: bandwidth limits, download lists, website mirroring, an honest comparison with <code data-no-translation=\"\">curl<\/code> and its successor <code data-no-translation=\"\">wget2<\/code>. The current GNU Wget series is <strong>1.25<\/strong>.<\/div>\n<p>The <strong>wget<\/strong> downloads files from the terminal and \u2014 the feature that made it irreplaceable \u2014 <strong>resumes interrupted downloads<\/strong>. Anyone who has lost a 2 GB ISO near the end of the progress bar on a bad connection knows why this matters. It remains the right tool for scripts, servers without a graphical interface, and unreliable connections.<\/p>\n<p><!-- more --><\/p>\n<h2>Where it came from<\/h2>\n<p>wget was born in 1995 as <strong>Geturl<\/strong>, written by Hrvoje Nik\u0161i\u0107. The name changed when the author learned of an Amiga program with the same name, and the <em>W<\/em> came from World Wide Web. It is part of the GNU Project, is written in portable C, and speaks HTTP, HTTPS, and FTP.<\/p>\n<p>It filled a real gap at the time: there was no single reliable program that downloaded over HTTP and FTP without depending on Perl. And in an era of dial-up connections and slow university links, surviving a network drop without human intervention was the feature, not a detail.<\/p>\n<p>A historical footnote: in 2010, analyst Chelsea Manning used wget inside the SIPRNet network to download the <strong>250 thousand diplomatic cables<\/strong> from the Net-Centric Diplomacy database, later handed to WikiLeaks. The Iraq and Afghanistan war records, often mentioned in the same sentence, came through a different route \u2014 they were exported directly from the CIDNE system, without wget. The tool is neutral; its use is not always so.<\/p>\n<h2>The basics<\/h2>\n<pre data-no-translation=\"\"><code class=\"language-bash\" data-no-translation=\"\"># baixa um arquivo no diretorio atual\nwget https:\/\/exemplo.com\/arquivo.iso\n\n# -c retoma de onde parou, se o arquivo ja existir parcialmente\nwget -c https:\/\/exemplo.com\/arquivo.iso\n\n# salva com outro nome\nwget -O ubuntu.iso https:\/\/exemplo.com\/arquivo.iso\n\n# salva em outro diretorio\nwget -P ~\/Downloads https:\/\/exemplo.com\/arquivo.iso\n\n# baixa em segundo plano, com log em wget-log\nwget -b https:\/\/exemplo.com\/arquivo-grande.iso\n<\/code><\/pre>\n<p>The <code data-no-translation=\"\">-c<\/code> is the reason the command exists. It tells the server to continue from the byte where the local file stopped instead of starting over. It works if the server supports partial requests \u2014 almost all do.<\/p>\n<p>A caveat almost nobody mentions: <code data-no-translation=\"\">-c<\/code> <strong>assumes<\/strong> that the local file with that name is the beginning of the remote file. If some other file with the same name is there, it requests the remainder starting at that size and appends it to what already exists \u2014 the result has the right size, corrupted contents, and no warning. Resume only what you started yourself.<\/p>\n<h2>When the network is bad<\/h2>\n<pre data-no-translation=\"\"><code class=\"language-bash\" data-no-translation=\"\"># tenta indefinidamente, com espera crescente de ate 30s entre tentativas\nwget -c --tries=0 --waitretry=30 https:\/\/exemplo.com\/arquivo.iso\n\n# desiste de uma tentativa que travar por mais de 30s\nwget -c --timeout=30 --tries=20 https:\/\/exemplo.com\/arquivo.iso\n\n# limita a banda, para nao engasgar a conexao da casa ou do escritorio\nwget --limit-rate=500k https:\/\/exemplo.com\/arquivo.iso\n<\/code><\/pre>\n<p>About <code data-no-translation=\"\">--waitretry<\/code>: it is not a fixed interval, it is a <em>ceiling<\/em>. wget waits 1 second after the first failure, 2 after the second, and so on up to the value you provided. The default is already 10 seconds, so <code data-no-translation=\"\">--waitretry=10<\/code> changes nothing \u2014 it is only worth specifying to increase it. The <code data-no-translation=\"\">--tries<\/code> also already defaults to 20; <code data-no-translation=\"\">--tries=0<\/code> is what means infinite.<\/p>\n<p>The <code data-no-translation=\"\">--limit-rate<\/code> is underrated: on a shared server, downloading at full speed hurts everyone's latency. Capping at 500 KB\/s is often the difference between a considerate download and a support ticket.<\/p>\n<h2>Multiple files at once<\/h2>\n<pre data-no-translation=\"\"><code class=\"language-bash\" data-no-translation=\"\"># um arquivo de texto com uma URL por linha\nwget -i lista-de-urls.txt\n\n# continuando e limitando a banda, para uma lista grande\nwget -c --limit-rate=1m -i lista-de-urls.txt\n\n# todos os PDFs de uma pagina, sem subir de diretorio\nwget -r -l 1 -np -A pdf https:\/\/exemplo.com\/documentos\/\n<\/code><\/pre>\n<p>In the last one, every flag matters: <code data-no-translation=\"\">-r<\/code> is recursive, <code data-no-translation=\"\">-l 1<\/code> limits depth to one level, <code data-no-translation=\"\">-np<\/code> (<em>no-parent<\/em>) prevents it from climbing to the parent directory, and <code data-no-translation=\"\">-A pdf<\/code> accepts only PDFs. Without <code data-no-translation=\"\">-np<\/code> and without <code data-no-translation=\"\">-l<\/code>, a recursive download can end up downloading the entire site.<\/p>\n<h2>Mirroring a website<\/h2>\n<pre data-no-translation=\"\"><code class=\"language-bash\" data-no-translation=\"\"># baixa uma pagina com tudo que ela precisa para abrir offline\nwget -p -k https:\/\/exemplo.com\/artigo.html\n\n# espelho completo do site, navegavel offline\nwget --mirror -p -k -P .\/copia https:\/\/exemplo.com\/\n<\/code><\/pre>\n<p><code data-no-translation=\"\">-p<\/code> fetches the page's images, CSS, and scripts; <code data-no-translation=\"\">-k<\/code> converts links to point to local files; <code data-no-translation=\"\">--mirror<\/code> is equivalent to <code data-no-translation=\"\">-r -N -l inf --no-remove-listing<\/code> \u2014 infinite recursion with timestamp checking.<\/p>\n<p>Two courtesies that prevent blocking: use <code data-no-translation=\"\">--wait=1<\/code> to avoid hammering the server, and respect <code data-no-translation=\"\">robots.txt<\/code>. There is <code data-no-translation=\"\">-e robots=off<\/code>, but ignoring the site's policy is your decision and often results in an IP block.<\/p>\n<h2>Headers, authentication, and certificates<\/h2>\n<pre data-no-translation=\"\"><code class=\"language-bash\" data-no-translation=\"\"># identificar-se como um navegador\nwget -U \"Mozilla\/5.0\" https:\/\/exemplo.com\/arquivo\n\n# enviar um cabecalho (ex.: token de API)\nwget --header=\"Authorization: Bearer SEU_TOKEN\" https:\/\/api.exemplo.com\/dados\n\n# autenticacao HTTP basica\nwget --user=usuario --ask-password https:\/\/exemplo.com\/privado\/arquivo\n<\/code><\/pre>\n<p>On forums, you will find suggestions to use <code data-no-translation=\"\">--no-check-certificate<\/code> when an SSL error occurs. It disables certificate verification and opens the way to interception. Certificate errors almost always mean the system clock is wrong or the CA package is outdated \u2014 fix the cause (<code data-no-translation=\"\">sudo apt install --reinstall ca-certificates<\/code>) instead of disabling the check.<\/p>\n<h2>wget or curl?<\/h2>\n<p>Both download files, but solve different problems:<\/p>\n<ul>\n<li><strong>wget<\/strong> wins for downloads: resumes automatically, is recursive, mirrors sites, and keeps trying when the network drops. It is the tool for <em>fetching files<\/em>.<\/li>\n<li><strong>curl<\/strong> wins for APIs: speaks many more protocols, builds complex requests, sends data, and naturally prints to standard output \u2014 it fits into pipes. It is the tool for <em>talking to services<\/em>.<\/li>\n<\/ul>\n<pre data-no-translation=\"\"><code class=\"language-bash\" data-no-translation=\"\">wget -O - https:\/\/exemplo.com\/script.sh | less   # wget imprimindo na saida\ncurl -L -O https:\/\/exemplo.com\/arquivo.iso       # curl salvando com o nome remoto\n<\/code><\/pre>\n<p>Notice <code data-no-translation=\"\">-L<\/code> in curl: it does not follow redirects by default, whereas wget does. This is the most common trap when swapping one for the other in a script.<\/p>\n<h2>And wget2<\/h2>\n<p>The GNU Project maintains <a href=\"https:\/\/gitlab.com\/gnuwget\/wget2\">wget2<\/a>, rewritten with parallel downloads, HTTP\/2 support, and compression \u2014 much faster on sites with many small files. Where packaged, it installs alongside without conflicts, using the binary <code data-no-translation=\"\">wget2<\/code>:<\/p>\n<pre data-no-translation=\"\"><code class=\"language-bash\" data-no-translation=\"\">sudo apt install wget2\nwget2 --version\n<\/code><\/pre>\n<p>The installed version varies considerably, though \u2014 check before relying on a new feature:<\/p>\n<pre data-no-translation=\"\"><code class=\"language-bash\" data-no-translation=\"\">wget --version | head -1\n<\/code><\/pre>\n<p>Ubuntu 24.04 LTS ships <strong>1.21.4<\/strong>; Debian 13 ships <strong>1.25.0<\/strong>. And there is one case that breaks the assumption: <strong>on Fedora, since version 40, the command <code data-no-translation=\"\">wget<\/code> is already wget2<\/strong> \u2014 the classic package was retired and replaced. Where both coexist (Debian, Ubuntu), wget2 installs alongside wget without conflict. Fedora's replacement proposal itself records the successor's gaps: except for WARC and FTP, it is compatible.<\/p>\n<h2>Check the download before using it<\/h2>\n<p>Downloading over an unstable connection with resuming, then writing straight to a USB drive without checking, is the quickest way to lose an afternoon to an installation that fails midway. Every distribution publishes a checksum file alongside the image:<\/p>\n<pre data-no-translation=\"\"><code class=\"language-bash\" data-no-translation=\"\">wget https:\/\/exemplo.com\/SHA256SUMS\nwget https:\/\/exemplo.com\/imagem.iso\n\nsha256sum -c SHA256SUMS --ignore-missing\n# imagem.iso: SUCESSO\n<\/code><\/pre>\n<p>The <code data-no-translation=\"\">--ignore-missing<\/code> avoids errors for other images listed in the file that you did not download. If the output says <em>FAILED<\/em>, the download is corrupted \u2014 delete it and download again, without <code data-no-translation=\"\">-c<\/code>.<\/p>\n<h2>To keep going<\/h2>\n<ul>\n<li><a href=\"\/en\/2017\/04\/usando-comando-dd-no-linux\/\">Using the dd command<\/a> \u2014 to write the ISO you just downloaded to a USB drive<\/li>\n<li><a href=\"\/en\/2017\/04\/500-comandos-do-linux\/\">500 Linux commands<\/a><\/li>\n<li><a href=\"https:\/\/www.gnu.org\/software\/wget\/manual\/wget.html\">Official GNU Wget manual<\/a><\/li>\n<\/ul>","protected":false},"excerpt":{"rendered":"<p>wget downloads files from the terminal and \u2014 the feature that made it irreplaceable \u2014 resumes interrupted downloads. Anyone who has lost a 2 GB ISO near the end of the progress bar on a poor connection knows why that matters. It continues \u2026 <a title=\"Using the wget command on Linux\" class=\"read-more\" href=\"https:\/\/www.linuxpro.com.br\/en\/2017\/04\/usando-comando-wget-no-linux\/\" aria-label=\"Read more about Usando o comando wget no Linux\">Read more<\/a><\/p>","protected":false},"author":0,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[28,2],"tags":[124,413,412,4,117,411],"class_list":["post-151","post","type-post","status-publish","format-standard","hentry","category-dicas","category-linux","tag-comandos","tag-curl","tag-download","tag-linux","tag-terminal","tag-wget"],"_links":{"self":[{"href":"https:\/\/www.linuxpro.com.br\/en\/wp-json\/wp\/v2\/posts\/151","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.linuxpro.com.br\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.linuxpro.com.br\/en\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/www.linuxpro.com.br\/en\/wp-json\/wp\/v2\/comments?post=151"}],"version-history":[{"count":6,"href":"https:\/\/www.linuxpro.com.br\/en\/wp-json\/wp\/v2\/posts\/151\/revisions"}],"predecessor-version":[{"id":1073,"href":"https:\/\/www.linuxpro.com.br\/en\/wp-json\/wp\/v2\/posts\/151\/revisions\/1073"}],"wp:attachment":[{"href":"https:\/\/www.linuxpro.com.br\/en\/wp-json\/wp\/v2\/media?parent=151"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.linuxpro.com.br\/en\/wp-json\/wp\/v2\/categories?post=151"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.linuxpro.com.br\/en\/wp-json\/wp\/v2\/tags?post=151"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}