If we want to know what is wget command and its syntax then you can read our previous post.
Read: wget command in unix
In this post, we will discuss a few examples of wget command.
1. Download Single File
This will download the sample.png file from our web site into user’s current working directory.
2. Resume Partial Downloaded File
We know one thing how much it pains when your internet connection is disconnected in the middle of large file downloading. If we have wget it is a rescue here and wget can resume download wherever it left off.
By using the option ‘-c’ in wget command we will resume our download from where it got disconnected.
3. Download Files in the background
We can download the files in the background using the option ‘-b’ in wget command.
4. Limiting Download Speed
By default wget command tries to use full bandwidth, however, there could also be a case that you are using shared internet, thus if you try are attempting to transfer the large file using wget, this might slow down Internet of other users.
This situation will be avoided if you limit the transfer speed using ‘–limit-rate‘ option in wget.
5. Download Multiple Files using ‘-i’ option
If you want to download multiple files using wget command , then first create a text file and add all URLs in the text file.
6. Increase Retry Attempts
By default wget command retries twenty times to make the download successful. We can increase the retry attempts using ‘–tries‘ option in wget.
This option becomes terribly helpful when you have internet connection problem and you are downloading a huge file , then there is a chance of failures in the download.
7. Redirect wget Logs to a log File using -o
We can redirect the wget command logs to a log file using ‘-o‘ option.
download_log.log file will be created in the user’s current directory.
8. Download Full website for local viewing.
–mirror : turn on options suitable for mirroring.
-p : download all files that are necessary to properly display a given HTML page.
–convert-links : after the download, convert the links in document for local viewing.
-P ./Local-Folder : save all the files and directories to the specified directory.
9. Reject file types while downloading.
When you are planning to download full website , then we can force wget command not to download images using ‘–reject’ option .
10. Downloading file from password protected site.
Another way to specify username and password is in the URL itself.
Either method reveals your password to anyone who bothers to run “ps”. To prevent the passwords from being seen, store them in .wgetrc or .netrc, and make sure to protect those files from other users with “chmod”.
If the passwords are really important, do not leave them lying in those files either edit the files and delete them after wget has started the download.