10 PRACTICAL EXAMPLES USING WGET COMMAND IN UNIX

wget-command-examples-unix

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

$wget http://wingsoftechnology.com/sample.png

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.

$wget -c http://wingsoftechnology.com/sample.png

3. Download Files in the background

We can download the files in the background using the option ‘-b’ in wget command.

$wget -b http://wingsoftechnology.com/sample.png

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.

$wget –limit-rate=100k http://wingsoftechnology.com/sample.png

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.

$cat download-list.txt
url_1
url_2
url_3

$wget -i download-list.txt

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.

$wget –tries=75 http://wingsoftechnology.com/sample.png

7. Redirect wget Logs to a log File using -o

We can redirect the wget command logs to a log file using ‘-o‘ option.

$wget -o download_log.log http://wingsoftechnology.com/sample.png

download_log.log file will be created in the user’s current directory.

8. Download Full website for local viewing.

$wget –mirror -p –convert-links -P ./<Local-Folder> website-url

Whereas

–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 .

$wget –reject=png Website-To-Be-Downloaded

10. Downloading file from password protected site.

$wget –ftp-user=<user-name> –ftp-password=<password> Download-URL

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.

Comments

comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: