Wget learn through examples
If you are on centos use yum to install it
yum install wget cd /home/downloads
If you are on windows, Ofcourse you can use your browser to download this. But i would still recommend to install wget on windows, since it is such a useful utility.
To install on windows, i would suggest installing windows terminal emulator MobaXterm. Once you have MobaXterm installed. Install wget using following command...
apt-get install wget
Once it is installed you can do man wget to look at the detailed usage of this command. I have put together some of the most use cases of wget in this post.
Lets first start with a simple case, lets say we want to download a file nti_minirator.exe from realtraps.com
wget http://www.realtraps.com/nti_minirator.exe --2019-08-17 22:58:36-- http://www.realtraps.com/nti_minirator.exe Resolving www.realtraps.com (www.realtraps.com)... 18.104.22.168 Connecting to www.realtraps.com (www.realtraps.com)|22.214.171.124|:80... connected. HTTP request sent, awaiting response... 301 Moved Permanently Location: http://realtraps.com/nti_minirator.exe [following] --2019-08-17 22:58:36-- http://realtraps.com/nti_minirator.exe Resolving realtraps.com (realtraps.com)... 126.96.36.199 Reusing existing connection to www.realtraps.com:80. HTTP request sent, awaiting response... 200 OK Length: 1399900 (1.3M) [application/octet-stream] Saving to: nti_minirator.exe 100%[======================================>] 1,399,900 1.05MB/s in 1.3s 2019-08-17 22:58:38 (1.05 MB/s) - nti_minirator.exe saved [1399900/1399900]
Instead of printing everything on the command prompt, we can log everything to a file using -o switch
wget http://www.realtraps.com/nti_minirator.exe -o logfile
If we cat the above file, we will see same log messages printed in the file
cat logfile | tail -5 1300K .......... .......... .......... .......... .......... 98% 12.1M 0s 1350K .......... ....... 100% 10.6M=1.3s 2019-08-17 22:59:04 (1.06 MB/s) - nti_minirator.exe.1 saved
One thing to notice here is that, since we downloaded the same file again, it saved the file with ".1" suffix. wget will keep appending and increment the counter
To overwrite the file use -O switch
wget http://www.realtraps.com/nti_minirator.exe -o logfile -O nti_minirator.exe
Without the -O switch, it would have appended .2, lets do ls to see, we should have only two files
ls nti_minir* nti_minirator.exe nti_minirator.exe.1
Lets look in to the log file, how many lines are there
wc -l logfile 43 logfile
Instead of overwriting the log file, we can append in to same log file using -a switch
wget http://www.realtraps.com/nti_minirator.exe -a logfile -O nti_minirator.exe wc -l logfile 86 logfile
There are some other useful command which I would like to expand in the future post. I am putting it down for reference in case you are interested.
wget http://www.realtraps.com/nti_minirator.exe -q -O nti_minirator.exe wget -i http://www.realtraps.com/nti_minirator.exe -o logfile -O nti_minirator.exe wget --limit-rate=1m http://www.realtraps.com/nti_minirator.exe wget -c http://www.realtraps.com/nti_minirator.exe wget -b http://www.realtraps.com/nti_minirator.exe wget --user-agent="Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0" http://www.realtraps.com/nti_minirator.exe wget --ftp-user=FTP_USERNAME --ftp-password=FTP_PASSWORD ftp://ftp.example.com/filename.tar.gz wget -m https://example.com wget -m -k -p https://example.com wget --no-check-certificate http://www.realtraps.com/nti_minirator.exe