Tuesday, January 16, 2018

Learn to use Wget command with 12 examples

http://linuxtechlab.com/learn-wget-command-12-examples

Every now & then we have to download files from internet, its
easy id you are using GUI but CLI it can be a bit difficult. WGET
command makes it easy for us to download files from internet using CLI.
Its extremely good utility & can handle all kinds of download.

1- Downloading single file

This
will start downloading the Nagios Core on your system & during
download you will be able to see percentage completed, amount of bytes
downloaded, current download speed & also time remaining for the
download to be complete.

2- Downloading file & storing with a different name

If we want to save the downloaded file with a different name than its default name, we can use ‘-O’ parameter with wget command to do so,

3- Limit download speed of the files

We
can limit the download limit of the files being downloaded, so that
whole network line is not choked up or other network related operations
are not affected. We can do this by using ‘- -limit-rate’ parameter

6- Downloading multiple files

If
there is list of URLs you need to download & don’t want to manually
start the next download once the previous completes, you can use ‘-I ’ parameter. But before we start downloading, we need to create a file with all the urls,

$ vi url.txt

& enter the URLs with a single URL in single line. After you have created the file, run the following command,

$ wget –I url.txt

This command will download all the files mentioned on those URl, once after another.

7- Increase total number of retries for the download URL

To increase the number of retries for the download, we can use ‘- – tries’ parameter,

8- For downloading files from anonymous FTP,

9- Replicate whole website

If you need to download all contents of a website, you can do so by using ‘- – mirror’ parameter,

$ wget –mirror -p –convert-links -P /home/dan xyz.com

Here, wget – mirror is command to download the website,-p, will download all files necessary to display HTML files properly,–convert-links, will convert links in documents for viewing,-P /home/dan, will save the file in /home/dan directory.

10-Download only a certain type of files

To download only a file with certain format type, use ‘-r -A’ parameters,

$ wget –r –A.txt Website_url

11-Restrict to download a certain file type

While downloading a website, if you don’t want to download a certain file type you can do so by using ‘- – reject’ parameter,