{"id":269,"date":"2010-01-14T00:22:58","date_gmt":"2010-01-14T05:22:58","guid":{"rendered":"http:\/\/nylinuxhelp.com\/blogs\/?p=269"},"modified":"2010-01-14T12:16:30","modified_gmt":"2010-01-14T17:16:30","slug":"download-several-files-part-1","status":"publish","type":"post","link":"https:\/\/nylinuxhelp.com\/blogs\/command-line\/download-several-files-part-1","title":{"rendered":"Download several files: part 1"},"content":{"rendered":"<h2>How to use wget; download many files with one command.<\/h2>\n<p>A typical way to download a file is to &#8220;right-click&#8221; on it and &#8220;save as&#8221; to a folder on your computer.\u00a0 Downloading a few files this way is not tedious.\u00a0 But if an audio book has 25 to 30 files you can bet I don&#8217;t want to do those manual moves over and over again.<\/p>\n<p>Using a terminal, there&#8217;s a faster way to download files.\u00a0 I&#8217;ll introduce now one of my often-used commands: <strong>wget<\/strong>.\u00a0 This command has many useful options.\u00a0 For example, you can download files, set up custom directory structures for your download(s), or see if a file exists without actually downloading it.<\/p>\n<p>Using the command (in simple terms): Open a terminal and type <strong>wget [options] [urls] <\/strong>at the prompt (usually a dollar sign).\u00a0 You can use one or several URLs.\u00a0 Options are (well&#8230;) optional.<\/p>\n<p>Here&#8217;s a practical example where you can download a gif image from the O&#8217;Reilly site linked below.\u00a0 When you open a Linux terminal, you are usually in your user&#8217;s &#8220;home&#8221; directory.\u00a0 This is fine for the purpose of this example.\u00a0 Issue the command<\/p>\n<pre>wget http:\/\/oreilly.com\/catalog\/covers\/0596009305_bkt.gif<\/pre>\n<p>Here&#8217;s what will happen: the file <strong>0596009305_bkt.gif<\/strong> gets downloaded and saved to your home folder.\u00a0 Cool right? But it was a bit of work (typing) just to download one file.\u00a0 <em>How does this save me time?<\/em><\/p>\n<p>Yes, the above example is overly-simplified.\u00a0 You can, if you wish, download any &#8220;.gif&#8221; or &#8220;.jpg&#8221; files from a given web address in the example below.\u00a0 It&#8217;s a time-saving single command, borrowed from the <a title=\"Download all images from a site\" href=\"http:\/\/www.commandlinefu.com\/commands\/view\/29\/download-all-images-from-a-site\" target=\"_blank\">commandlinefu website<\/a> mentioned in the &#8220;cool and advanced uses of wget&#8221; link below.<\/p>\n<pre>wget -r -l1 --no-parent -nH -nd -A\".gif,.jpg\" http:\/\/example.com\/images<\/pre>\n<p>*Change the &#8220;example.com\/images&#8221; to a valid web address.\u00a0 The options above (explained) are:<\/p>\n<ul>\n<li>-r for &#8220;recursive&#8221;<\/li>\n<li>-l1 only get files in the &#8220;images&#8221; directory (don&#8217;t dive into subdirectories)<\/li>\n<li>&#8211;no-parent and -nH and -nd : ignore directory structure (no directories\u2014just get the files)<\/li>\n<li>&#8220;-A&#8221; is the &#8220;accept list&#8221; for files of type [.gif and .jpg].\u00a0 It&#8217;s case-sensitive, so it would not download files ending in &#8220;.JPG&#8221;, so if you needed those too, specify with -A&#8221;.gif,.jpg,.JPG&#8221;<\/li>\n<\/ul>\n<p>You can <a title=\"Linux command directory for wget\" href=\"http:\/\/www.oreillynet.com\/linux\/cmd\/cmd.csp?path=w\/wget\" target=\"_blank\">find more wget info and options here<\/a>.\u00a0 For <a title=\"commandlinefu - commands using wget\" href=\"http:\/\/www.commandlinefu.com\/commands\/using\/wget\" target=\"_blank\">really cool and advanced uses of wget, see this page<\/a>.<\/p>\n<p>I&#8217;ll post another awesome usage of wget in another post.\u00a0 Thanks for reading.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>How to use wget; download many files with one command. A typical way to download a file is to &#8220;right-click&#8221; on it and &#8220;save as&#8221; to a folder on your computer.\u00a0 Downloading a few files this way is not tedious.\u00a0 But if an audio book has 25 to 30 files you can bet I don&#8217;t [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14,7,23],"tags":[26,31],"class_list":["post-269","post","type-post","status-publish","format-standard","hentry","category-linux-apps","category-command-line","category-use-linux","tag-commands","tag-wget"],"_links":{"self":[{"href":"https:\/\/nylinuxhelp.com\/blogs\/wp-json\/wp\/v2\/posts\/269","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nylinuxhelp.com\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nylinuxhelp.com\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nylinuxhelp.com\/blogs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nylinuxhelp.com\/blogs\/wp-json\/wp\/v2\/comments?post=269"}],"version-history":[{"count":49,"href":"https:\/\/nylinuxhelp.com\/blogs\/wp-json\/wp\/v2\/posts\/269\/revisions"}],"predecessor-version":[{"id":317,"href":"https:\/\/nylinuxhelp.com\/blogs\/wp-json\/wp\/v2\/posts\/269\/revisions\/317"}],"wp:attachment":[{"href":"https:\/\/nylinuxhelp.com\/blogs\/wp-json\/wp\/v2\/media?parent=269"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nylinuxhelp.com\/blogs\/wp-json\/wp\/v2\/categories?post=269"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nylinuxhelp.com\/blogs\/wp-json\/wp\/v2\/tags?post=269"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}