Difference between revisions of "Wget"

From Christoph's Personal Wiki
Jump to: navigation, search
m (Wget (command) moved to Wget)
Line 1: Line 1:
{{lowercase|wget}}
 
 
'''wget''' — The non-interactive network downloader.
 
'''wget''' — The non-interactive network downloader.
  
 
==Usage==
 
==Usage==
 
*Mirror an entire web site
 
*Mirror an entire web site
  wget -m http://www.example.com
+
  wget -m <nowiki>http://www.example.com</nowiki>
  
 
*Download all pages from a site and the pages the site links to (one-level deep):
 
*Download all pages from a site and the pages the site links to (one-level deep):
  wget -H -r --level=1 -k -p http://www.example.com
+
  wget -H -r --level=1 -k -p <nowiki>http://www.example.com</nowiki>
  
 
*Resume large file download:
 
*Resume large file download:
  wget -c --output-document=Bill_Maher_-_New_Rules_2007-03-15.avi "http://www.youtube.com/watch%3Fv%3DhFjRI5jJ5I4&usg=AL29H23P1UQZRf0yDqRBlwB0jyfSLbzzhg"
+
  wget -c --output-document=Bill_Maher_-_New_Rules_2007-03-15.avi "<nowiki>http://www.youtube.com/watch%3Fv%3DhFjRI5jJ5I4&usg=AL29H23P1UQZRf0yDqRBlwB0jyfSLbzzhg</nowiki>"
  
 
*Schedule hourly downloads of a file
 
*Schedule hourly downloads of a file
  wget --output-document=traffic_$(date +\%Y\%m\%d\%H).gif "http://sm3.sitemeter.com/YOUR_CODE"
+
  wget --output-document=traffic_$(date +\%Y\%m\%d\%H).gif "<nowiki>http://sm3.sitemeter.com/YOUR_CODE</nowiki>"
  
 
*Automatically download music (by [http://www.veen.com/jeff/archives/000573.html Jeff Veen]):
 
*Automatically download music (by [http://www.veen.com/jeff/archives/000573.html Jeff Veen]):
Line 19: Line 18:
 
where <code>mp3_sites.txt</code> lists your favourite (legal) download sites.
 
where <code>mp3_sites.txt</code> lists your favourite (legal) download sites.
  
== Download multiple files ==
+
==Download multiple files==
 
* Create variable that holds all URLs and then using 'BASH for loop' to download all files:
 
* Create variable that holds all URLs and then using 'BASH for loop' to download all files:
 
  % URLS="<nowiki>http://www.example.com/foo.tar.gz ftp://ftp.example.org/pub/bar.tar.gz</nowiki>"
 
  % URLS="<nowiki>http://www.example.com/foo.tar.gz ftp://ftp.example.org/pub/bar.tar.gz</nowiki>"
Line 34: Line 33:
  
 
# invoke wget-list without arguments
 
# invoke wget-list without arguments
 
 
while [ `find .wget-list -size +0` ]
 
while [ `find .wget-list -size +0` ]
 
  do
 
  do
Line 65: Line 63:
 
</pre>
 
</pre>
  
== See also ==
+
==See also==
* [[Curl (command)|curl]]
+
*[[curl]]
* [[Wput (command)|wput]]
+
*[[wput]]
* [[Rsync (command)|rsync]]
+
*[[rsync]]
* [[Axel (command)|axel]]
+
*[[axel]]
* [http://prozilla.genesys.ro/ prozilla]
+
*[http://prozilla.genesys.ro/ prozilla]
  
== External links ==
+
==External links==
* [http://www.gnu.org/software/wget/manual/ GNU Wget Manual] &mdash; last update: 15-Jun-2005
+
*[http://www.gnu.org/software/wget/manual/ GNU Wget Manual] &mdash; last update: 15-Jun-2005
* [http://www.lifehacker.com/software/top/geek-to-live--mastering-wget-161202.php Geek to Live: Mastering Wget]
+
*[http://www.lifehacker.com/software/top/geek-to-live--mastering-wget-161202.php Geek to Live: Mastering Wget]
* [http://www.cyberciti.biz/nixcraft/vivek/blogger/2005/06/linux-wget-your-ultimate-command-line.php wget: your ultimate command line downloader]
+
*[http://www.cyberciti.biz/nixcraft/vivek/blogger/2005/06/linux-wget-your-ultimate-command-line.php wget: your ultimate command line downloader]
  
{{stub}}
 
 
[[Category:Linux Command Line Tools]]
 
[[Category:Linux Command Line Tools]]

Revision as of 01:51, 26 April 2007

wget — The non-interactive network downloader.

Usage

  • Mirror an entire web site
wget -m http://www.example.com
  • Download all pages from a site and the pages the site links to (one-level deep):
wget -H -r --level=1 -k -p http://www.example.com
  • Resume large file download:
wget -c --output-document=Bill_Maher_-_New_Rules_2007-03-15.avi "http://www.youtube.com/watch%3Fv%3DhFjRI5jJ5I4&usg=AL29H23P1UQZRf0yDqRBlwB0jyfSLbzzhg"
  • Schedule hourly downloads of a file
wget --output-document=traffic_$(date +\%Y\%m\%d\%H).gif "http://sm3.sitemeter.com/YOUR_CODE"
wget -r -l1 -H -t1 -nd -N -np -A.mp3 -erobots=off -i mp3_sites.txt

where mp3_sites.txt lists your favourite (legal) download sites.

Download multiple files

  • Create variable that holds all URLs and then using 'BASH for loop' to download all files:
% URLS="http://www.example.com/foo.tar.gz ftp://ftp.example.org/pub/bar.tar.gz"
  • Use for loop as follows:
% for u in $URLS; do wget $u; done
  • You can also put a list of the URLs in a file and download using the -i option:
% wget -i download.txt

Automating/scripting download process

#!/bin/sh
# wget-list: manage the list of downloaded files

# invoke wget-list without arguments
while [ `find .wget-list -size +0` ]
 do
  url=`head -n1 .wget-list`
   wget -c $url
   sed -si 1d .wget-list
 done
#/bin/sh
# wget-all: process .wget-list in every subdirectory
# invoke wget-all without arguments

find -name .wget-list -execdir wget-list ';'
#!/bin/sh
# wget-dirs: run wget-all in specified directories
# invoking: wget-dirs <path-to-directory> ...

for dir in $*
  do
      pushd $dir
      wget-all
      popd
  done
wget-all

See also

External links