Wget command in Linux is used to download files from the web using HTTP, HTTPS, and FTP protocols. In other words we can say that wget is non-interactive command line downloader tool for Linux systems. It also supports downloading files through HTTP proxies.
Here non-interactive means that it can work in the background, while the user is not logged on. When we do the minimal installation of Linux distributions then wget command is not installed, So to install wget on Linux distributions, run
$ sudo yum install -y wget // CentOS 7 / RHEL 7 $ sudo dnf install -y wget // CentOS 8/ RHEL 8/ Rocky Linux 8 $ sudo apt install -y wget // Ubuntu / Debian $ sudo pacman -S wget // Arch Linux $ sudo zypper install wget // OpenSUSE
In this tutorial, we will cover 12 useful wget command examples. These examples will help you to start using wget command like a professional. So let’s deep dive into examples.
1) Downloading a single file with wget
To download a file using wget command, simply type wget command followed by the absolute path of file, example is shown below:
$ wget https://download.rockylinux.org/pub/rocky/8/isos/x86_64/Rocky-8.4-x86_64-minimal.iso
This command will download Rocky Linux 8 ISO file in the user’s current working directory.
2) Resume partial downloaded file (-c)
There are some scenarios where we start downloading a large file but in the middle Internet got disconnected , so using the option ‘-c’ option in wget command we can resume our download from where it got disconnected. Example is shown below,
$ wget -c https://download.rockylinux.org/pub/rocky/8/isos/x86_64/Rocky-8.4-x86_64-minimal.iso
3) Download Files in the background (-b)
Use ‘-b’ option in wget command to download files in the background. This option becomes very useful where the file is too large and you want to use terminal for other tasks.
$ wget -b https://download.rockylinux.org/pub/rocky/8/isos/x86_64/Rocky-8.4-x86_64-dvd1.iso Continuing in background, pid 4505. Output will be written to ‘wget-log’.
As we can see above that downloading progress is capture in ‘wget-log’ file in user’s current directory. Use tail command to view status of download.
$ tail -f wget-log 2300K .......... .......... .......... .......... .......... 0% 48.1K 18h5m 2350K .......... .......... .......... .......... .......... 0% 53.7K 18h9m 2400K .......... .......... .......... .......... .......... 0% 52.1K 18h13m 2450K .......... .......... .......... .......... .......... 0% 58.3K 18h14m 2500K .......... .......... .......... .......... .......... 0% 63.6K 18h14m 2550K .......... .......... .......... .......... .......... 0% 63.4K 18h13m 2600K .......... .......... .......... .......... .......... 0% 72.8K 18h10m 2650K .......... .......... .......... .......... .......... 0% 59.8K 18h11m 2700K .......... .......... .......... .......... .......... 0% 52.8K 18h14m 2750K .......... .......... .......... .......... .......... 0% 58.4K 18h15m 2800K .......... .......... .......... .......... .......... 0% 58.2K 18h16m 2850K .......... .......... .......... .......... .......... 0% 52.2K 18h20m
4) Limiting download speed in wget command
By default wget command try to use full bandwidth , but there may be a case that you are using shared internet , so if you try to download huge file using wget , this may slow down Internet of other users. This situation can be avoided if you limit the download speed using ‘–limit-rate’ option.
$ wget --limit-rate=100k https://download.rockylinux.org/pub/rocky/8/isos/x86_64/Rocky-8.4-x86_64-dvd1.iso
In the above wget command, we have set the download limit as 100K.
5) Download multiple files with wget
If you want to download multiple files using wget command , then first create a text file and add all URLs in that text file. Example is shown below:
$ cat download-list.txt https://download.rockylinux.org/pub/rocky/8/isos/x86_64/Rocky-8.4-x86_64-dvd1.iso https://releases.ubuntu.com/20.04.2.0/ubuntu-20.04.2.0-desktop-amd64.iso https://download.opensuse.org/distribution/leap/15.3/iso/openSUSE-Leap-15.3-DVD-x86_64-Current.iso
Now run below command,
$ wget -i download-list.txt
Above wget command will start downloading the ISO files sequentially.
6) Increase Retry Attempts in wget
We can increase the retry attempts using ‘–tries’ option in wget. By default wget command retries 20 times to make the download successful.
This option becomes very useful when you have problem with your internet connection and you are downloading a large file.
$ wget --tries=75 https://download.opensuse.org/distribution/leap/15.3/iso/openSUSE-Leap-15.3-DVD-x86_64-Current.iso
Above wget command will try to download the file max 75 times .
7) Redirect wget command output to a log File
We can redirect the wget command output to a log file using ‘-o’ option. Example is demonstrated below,
$ wget -o download.log https://releases.ubuntu.com/20.04.2.0/ubuntu-20.04.2.0-desktop-amd64.iso
download.log file will be created automatically in the user’s current directory.
8) Download complete website for local viewing
Using wget command we can download the complete website for local viewing, syntax is show below,
$ wget --mirror -p --convert-links -P ./<Local-Folder> website-URL
Where
- –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) Setting Download quota in wget
We can force wget command to quit downloading when download size exceeds certain size. Use ‘-Q‘ option in wget command to set download quota.
$ wget -Q10m -i download-list.txt
Note that quota will never affect downloading a single file. So if you specify wget -Q10m ftp://wuarchive.wustl.edu/ls-lR.gz, all of the ls-lR.gz will be downloaded. The same goes even when several URLs are specified on the command-line. However, quota will work only when retrieving either recursively, or from an input file. Therefore you may safely type ‘wget -Q10m -i download-list.txt‘ download will be aborted when the quota is exceeded.
11) Downloading file from password protected site
wget commands
$ wget --ftp-user=<user-name> --ftp-password=<password> Download-URL or $ wget --user <user_name> --password <password> http://<url-path>/file_to_be_downloaded
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.
12) Downloading file by skipping certificate checks
There are some scenarios where we want to download file from https ports and want to skip certificate checks, so it can accomplished by using option “–no-check-certificate” in wget command,
$ wget https://about.gitlab.com/ --no-check-certificate
Downloading Oracle Java using wget command from https portal and skip certificate checks
$ wget --header "Cookie: oraclelicense=accept-securebackup-cookie" https://download.oracle.com/otn-pub/java/jdk/12.0.1+12/69cfe15208a647278a19ef0990eea691/jdk-12.0.1_linux-x64_bin.rpm --no-check-certificate
Downloading Files via Proxy
There are some situations where our system is running behind the proxy server, so in such situations first we need to set proxy and then we can use wget command to download file from the internet. To set proxy on the command line use the following variables and export command
$ export http_proxy=http://<Your-Proxy-IP>:<Proxy-Port> $ export https_proxy=http://<Your-Proxy-IP>:<Proxy-Port> $ export ftp_proxy=http://<Your-Proxy-IP>:<Proxy-Port>
In Case user name and password is required for proxy to work then use the followings
$ export http_proxy=http://<user-name>:<password>@<Your-Proxy-IP>:<Proxy-Port> $ export https_proxy=http://<user-name>:<password>@<Your-Proxy-IP>:<Proxy-Port> $ export ftp_proxy=http://<user-name>:<password>@<Your-Proxy-IP>:<Proxy-Port>
Additional Example
Download and Extract tar file with single wget command
Let’s suppose we want to download latest version of WordPress tar file and want to extract it under specific folder like /var/www/html, so to accomplish this task using below wget command,
# wget -q -O - http://wordpress.org/latest.tar.gz | tar -xzf - --strip-components=1 -C /var/www/html
That’s all from this tutorial, I hope you have found these wget command examples are very informative. Please do share your valuable feedback and comments in the comments section below.
Another useful example – download and extract archive to specific directory
wget -q -O – ‘http://wordpress.org/latest.tar.gz’ | tar -xzf – –strip 1 -C /path/to
Pradeep should include this in his examples, as this was the exact one I was looking for. I noticed something was running on our system under wget -qO- -O and I couldn’t figure out if this was a typo or what, so thanks for clearing it up for me. Took a lot from this, just wish it was more expansive!