Basic WGET usage examples

If you have ever used a relatively modern flavor of UNIX, you likely used a tool called wget. It comes as a standard piece of almost every single UNIX variant, Linux included. Here are some ways that I use it on a daily basis:

Download file


Downloading files with different names


Multiple downloads using different protocols


Using an input file

You can use an input file that contains a list of URLs to download, like so:

wget -i ~/Downloads/urls-for-wget.txt

Resume incomplete download

Sometimes a download is interrupted in the middle. To resume a partial download use the -c option, like so:

wget -c

Download files in the background

Using the option -b sends wget to the background and also saves the output to a log file:

wget -b ~/Downloads/wget-log.txt

Throttling download speeds

To limit the download speed, use the --limit-rate option:

wget --limit-rate=100k

Performing downloads with authentication

Some sites restrict access to content by requiring a username and password. wget can handle that:

wget --user=joeschmoe --password=p4sswOrd!

More information

Of course, you can mix and match all of these options into a single command, like so:

wget -c -b -a ./wget-log --limit-rate=100k

You can also go much further than what I described above. The script below will check the web page for the latest listed version of wget and then download it and its signature file if the online version is newer than the local one.

wget -qN $(wget -qO- \
          | grep tar | cut -d\" -f6 \
          | tail -n4 | grep gz \
          | sed "s|^||")

For more information, check online or use man or info.


Comments powered by Disqus