The “wget” Command in Linux [14 Practical Examples]

The wget which stands for “web get”, is a free command-line utility. Provided and authorized by the GNU General Public License (GPL), this package offers both non-interactive and recursive file-downloading facilities from the command prompt. Along with the retrieval of files, using wget Command in Linux you can also control tons of features like file types/ names, the number of files/ retrying attempts as well as downloading speed.

A. Description

wget allows users to download files from networks using protocols like HTTP, HTTPS, FTP, and FTPS. The non-interactive downloading occurs in the background while a user is either disconnected or busy with another process. It utilizes recursiveness by continuously attempting until a file is entirely retrieved. The wget Command in Linux also downloads complete HTML/ XHTML pages and replicates the content structure to browse the websites locally.

B. Syntax

The syntax of the wget command simply contains single or multiple options and then the desired URL/s.

wget [Option] … [URL] …
Note: In the above syntax the 3 dots after each square bracket indicate that multiple OPTIONs and URLs can be used at a time.

C. Options

wget Command in Linux offers options to modify your downloading experience. However, you will find the most useful one’s here for your convenience. For any further features, you can always look at the man page.

man wget

Useful Options

  • – b ( Downloads file in the background)
  • – c ( Continues interrupted downloads)
  • – i (Downloads multiple files)
  • – t /–tries = [number] (Fixes the number of retry attempts for interrupted downloads)
  • – m/– mirror (Mirrors a website locally for offline browsing)
  • – r (Turns on Recursive retrieval of files, default value = 5)
  • – A/ — accept “*.” (Downloads only specific file type)
  • – R/– reject  “*.” (Rejects downloads for specific file type)
  • – O, Upper case (Downloads file with a different name)
  • – p ( Downloads in a specific directory)
  • — limit-rate = [amount] ( Limits bandwidth/speed while downloading)
  • — no-check-certificate ( Ignores SSL certification check)

NB: The options in Linux CLI(Command Line Interface) are all case-sensitive, So be cautious while using them.

Installing “wget” Command in Linux

Most versions of Linux have the wget command pre-installed. You can find out whether you have it on your machine or not by typing the command wget itself.

wget

Your system will print out the following message if you already have it installed:Message to user if wget is already installedOtherwise, you will get the following text:Message to user if wget is not installed.In this case, don’t be overwhelmed. You can install wget package within a minute by following the instructions below.

Steps to Follow:

➊  At first open the Ubuntu Terminal

➋   Type the following in your command prompt:

sudo apt-get install wget

➌ Type your password

➍ Now, press ENTER

Output:

Upon completion of these four steps, wget will be installed on your machine.Installing wget command.

Practical Examples of the “wget” Command in Linux

With the wget Command in Linux, you will be able to enhance your downloading experience to a great extent. Here are some practical examples of wget command for your frequent use.

Example 1: Simply Download a Single File or Webpage Using the “wget” Command in Linux.

You can download a single file or webpage using the wget command in Linux. All you need to do is provide your URL next to the wget command.

Wget <URL>

In this example, I will download the homepage of the linuxsimply website. To do so you may follow the given steps.

Steps to Follow:

➊ At first open the Ubuntu Terminal.

➋ Type the following command in the command prompt:

wget https://linuxsimply.com/

➌ Now, press the ENTER button.

Output:

In this image, you can see that I have downloaded the desired homepage using the wget command. It has been saved in my current directory as “index.html”.Downloading a single file using wget command.

NB: You can find out your current directory where the file has been saved by typing pwd. The command ls will show you the downloaded file in your current directory.
Seeing downloaded file using ls command.

Similar Readings


Example 2: Downloading a Single File with Your Given Name Using the “wget” Command in Linux.

Using the wget command with the -O (Upper Case)  option, you can download a single file under a different name from your terminal. In this example, I will again download the homepage of the linuxsimply website. This time I will save it as “homepage.html”. To do so you may follow the given instructions.

Wget -O <URL>

You may follow the given steps to execute this command.

Steps to Follow:

➊ At first open the Ubuntu Terminal.

➋ Type the following command in the command prompt:

wget -O homepage.html https://linuxsimply.com/

➌ Now, press the ENTER button.

Output:

In this image, you can see that I have downloaded the desired homepage using the wget command. It has been saved in my current directory as “homepage.html”.Downloading file under a different name using wget command.

Example 3: Downloading Multiple Files at Once Using the “wget” Command in Linux.

Using the wget command, you can download multiple files at once. You will be able to download from both HTTP and FTP protocols in a single command. In this example, I will download both the homepage and commands page of the linuxsimply website. To do so you can follow the given steps.

wget <URL1> <URL2>

You may follow the given steps to execute this command.

Steps to Follow:

➊ At first open the Ubuntu Terminal.

➋ Type the following command in the command prompt:

wget https://linuxsimply.com/ https://linuxsimply.com/commands/

➌ Now, press the ENTER button.

Output:

In this image, you can see that I have downloaded both the homepage and command page using the wget command. The homepage has been saved in my current directory as “index.html” and the command page has been saved as “index.html.1”.Downloading multiple files using wget command.

Example 4: Download Multiple Files from Another File Using the “wget” Command in Linux.

You can use a particular file to download single or multiple files using the -i option with the wget command. The links found in this file will be downloaded directly to your system. You may use a TEXT or HTML file. In this example, I will download 3 pdf files from the URLs provided in the “text.txt” file. In this case, the URLs must be written in separate lines.  To do so you can follow the given steps.

wget -i  <File>

You may follow the given steps to execute this command.

Steps to Follow:

➊ At first open the Ubuntu Terminal.

➋ Type the following command in the command prompt:

wget -i text.txt

➌ Now, press the ENTER button.

Output:

In this image, you can see that I have downloaded 3 pdf files using the wget command. The files were downloaded on my machine serially one after another.Downloading multiple files from another file using wget command.

Example 5: Downloading Files to a Specific Directory Using the “wget” Command in Linux.

You can download files in your desired location using – P (Upper Case) option with the wget command. In this example, I will download the 50 Most Used Linux Commands pdf.pdf file from the linuxsimply website to my Documents directory. To do so you can follow the given steps.

wget -P <path> <File>

You may follow the given steps to execute this command.

Steps to Follow:

➊ At first open the Ubuntu Terminal.

➋ Type the following command in the command prompt:

wget -P Documents https://linuxsimply.com/wp-content/uploads/2022/11/50-Most-Used-Linux-Commands-pdf.pdf

➌ Now, press the ENTER button.

Output:

In this image, you can see that I have downloaded the file to my desired location using the wget command. Then, I listed the contents of the Documents directory using the ls command to see the downloaded file.Downloading files to specific directory using wget command.

Example 6: Downloading Files in the Background Using the “wget” Command in Linux.

Using the wget command with the option -b you can download files in the background. You can be disconnected while the download occurs. The output will be saved in a different file in the current directory along with the file. You can open the specific log file to see the downloading details. In this example, I will download the Bash Terminal Keyboard Shortcuts for Editing.pdf file from the linuxsimply website. To do so you can go through the following steps.

wget -P <path> <File>

You may follow the given steps to execute this command.

Steps to Follow:

➊ At first open the Ubuntu Terminal.

➋ Type the following command in the command prompt:

wget -b https://linuxsimply.com/wp-content/uploads/2022/11/Bash-Terminal-Keyboard-Shortcuts-for-Editing.pdf

➌ Now, press the ENTER button.

Output:

In this image, you can see that I am downloading the mentioned file in the background using the wget command. The output for my command was saved in the “wget-log.1” file in my current directory.Downloading Files in the Background using wget command.

Example 7: Limiting Downloading Speed for Files Using the “wget” Command in Linux.

Using the wget command with the option – – limit-rate you can limit the downloading speed. In this example, I will download the Emacs Editor Keybindings or Shortcuts.pdf file from the linuxsimply with a limited bandwidth of 50KBs. To do so you can go through the following steps.

wget --limit-rate=[value] <File>

You may follow the given steps to execute this command.

Steps to Follow:

➊ At first open the Ubuntu Terminal.

➋ Type the following command in the command prompt:

wget --limit-rate=50k https://linuxsimply.com/wp-content/uploads/2022/12/Emacs-Keybindings-or-Shortcuts-in-Linux.pdf

➌ Now, press the ENTER button.

Output:

In this image, you can see that I am downloading the mentioned file with a bandwidth of almost 50KB/s using the wget command.Limiting downloading speed for files usning wget command.

Example 8: Resuming Unfinished Downloads Using the wget Command in Linux.

You can resume your unfinished downloads with option -c of the wget command. In this example, I retrieved the partially downloaded homepage of the linuxsimply website. At first, I interrupted my ongoing download by pressing CTRL+Z. Then, I resumed downloading using the -c option. To do so you can go through the following steps.

wget -c <File>

You may follow the given steps to execute this command.

Steps to Follow:

➊ At first open the Ubuntu Terminal.

➋ Type the following command in the command prompt:

wget -c https://linuxsimply.com/

➌ Now, press the ENTER button.

Output:

In this image, you can see that the first downloading attempt was interrupted. Then I retrieved the partially downloaded file using the wget command.Resuming unfinished downloads using wget commands.


Similar Readings


Example 9: Downloading files recursively Using the “wget” Command in Linux

You can download files recursively with option -r of the wget command. In this example, I want to download all the files from the Free downloads page of the linuxsimply website recursively. You may do so by following the given steps

wget -r <URL>

You may follow the given steps to execute this command.

Steps to Follow:

➊ At first open the Ubuntu Terminal.

➋ Type the following command in the command prompt:

wget -r https://linuxsimply.com/free-downloads/

➌ Now, press the ENTER button.

Output:

In this image, you can see that at first without any option the wget command downloaded only the Free downloads page and saved it as “index.html.1”. I used the -r option to download all the files recursively. Since the downloads will take a lot of time I am doing it in the background with option -b and saving the output in the “wget-log” file. You can see the latest download output by typing the command tail before your log file. My output shows that the downloads are still occurring recursively with the wget command in Linux.Downloading files recursively usinng wget command.

Example 10: Selecting Certain File Types While Downloading Using the “wget” Command in Linux

You can select certain types of files while downloading with the option -A/–Accept of the wget command. In this example, I want to download only the .pdf files from the Free downloads page of the linuxsimply website. You may do so by following the given steps.

wget -A”.FileType” <URL>

You may follow the given steps to execute this command.

Steps to Follow:

➊ At first open the Ubuntu Terminal.

➋ Type the following command in the command prompt:

wget -A”*.pdf”  https://linuxsimply.com/free-downloads/

➌ Now, press the ENTER button.

Output:

In this image, you can see that I used the -A option along with the -r option. This is because the command needs to look recursively for the .pdf files. The wget command with the -A option saves each file. If the file does not match .pdf extension, it removes that file immediately. In this way, I am downloading only the .pdf files from the Free downloads page.Selecting certain file types while downloading using wget command.

Example 11: Rejecting a Certain File Type While Downloading Using the “wget” Command in Linux

You can reject certain types of files while downloading with the option -R/–Reject of the wget command. In this example, I want to reject downloading files with .tmp, .html, .css, and .js extensions from the Free downloads page of the linuxsimply website. You can follow the process below to do so.

wget -R FileType/s  <URL>

You may follow the given steps to execute this command.

Steps to Follow:

➊ At first open the Ubuntu Terminal.

➋ Type the following command in the command prompt:

wget -R tmp,html,css,js  https://linuxsimply.com/free-downloads/

➌ Now, press the ENTER button.

Output:

In this image, you can see that I used the -R option along with the -r option. This is because the command needs to look recursively for the .tmp, .html, .css, and .js extensions. The wget command with the -R option saves each file. If the file matches with any of the .tmp, .html, .css, and .js extensions, it removes that file immediately. In this way, I am not downloading .tmp, .html, .css, and .js files from the Free downloads page.Rejecting certain file types while downloading using wget command.

Example 12: Setting Numbers of Retrying Attempts for Downloading Using the “wget” Command in Linux

Using the wget command with the -t/–tries option, you can set the number of retrying attempts for interrupted downloads. In this example, I set the number of attempts to 2. The wget command will try to download the file twice if it faces any interruptions.

wget --tries=[number] <File> 

You may follow the given steps to execute this command.

Steps to Follow:

➊ At first open the Ubuntu Terminal.

➋ Type the following command in the command prompt:

wget -tries=2 --limit-rate=50k  https://linuxsimply.com/wp-content/uploads/2022/12/Untitled-design.gif

➌ Now, press the ENTER button.

Output:

In this image, you can see that I have fixed the retry attempts for download to 2. I also limited the bandwidth to 50KB/s. The desired file got interrupted after downloading 60%. The wget command tried to retrieve the file twice. After 2 failed attempts the downloading process stopped.Setting number of retrying attempts for downloading using wget command.

Example 13: Mirroring an Entire Website Using the “wget” Command in Linux

Using the wget command with the -m/–mirror option, you can download a full website on your local machine. This is called mirroring a website. You will be able to browse the mirrored website remotely even when you are offline. In this example, I will mirror the linuxsimply website. To do so you can follow the steps below.

wget --mirror -p --convert-links <website_URL> 
  • -p ( Downloads all necessary files to display .html pages)
  • –convert-links ( After downloading links convert them into documents for local view)

You may follow the given steps to execute this command.

Steps to Follow:

➊ At first open the Ubuntu Terminal.

➋ Type the following command in the command prompt:

wget --mirror -p --convert-links -P Downloads  https://linuxsimply.com/

➌ Now, press the ENTER button.

Output:

In the first image, you can see that I have downloaded the desired website in my Downloads directory using the wget command. It mirrored all the hierarchy and files for local browsing in my system.Mirroring a website using wget command.In this image, you can see the local version of the downloaded website.View of the mirrored website for local browsing.

Example 14: Ignoring SSL Certification Check While Downloading Using the “wget” Command in Linux

Using the wget command with the option –no-check-certificate you can avoid the SSL certification check of HTML websites. In this example, I will download the homepage of the SOFTEKO website without checking the certificate. To do so you can go through the following steps.

wget --no-check-certificate  <URL>

You may follow the given steps to execute this command.

Steps to Follow:

➊ At first open the Ubuntu Terminal.

➋ Type the following command in the command prompt:

wget --no-check-certificate https://www.softeko.co/

➌ Now, press the ENTER button.

Output:

In this image, you can see that I am downloading the mentioned website ignoring its SSL certification check using the wget command. The webpage was saved as “index.html.1” in my current directory.Ignoring SSL certification check using wget command.

Conclusion

In this article, I have tried to show you the frequent uses of the wget command in Linux. You can always combine one or more options demonstrated here to get a full experience. I hope these practical examples will help you through your journey with the command line and make you a power user of LINUX.


Similar Readings

Rate this post
Anonnya Ghosh

Anonnya Ghosh

Hello there! I am Anonnya Ghosh, a Computer Science and Engineering graduate from Ahsanullah University of Science and Technology (AUST). Currently, I am working as a Linux Content Developer Executive at SOFTEKO. The strong bond between Linux and cybersecurity drives me to explore this world of open-source architecture. I aspire to learn new things further and contribute to the field of CS with my experience. Read Full Bio

We will be happy to hear your thoughts

Leave a reply

LinuxSimply
Logo