Example of using the wget command on FreeBSD

Wget is a command line utility in the form of a command line that is used to download files from the web on Linux or Unix BSD. wget command line is a free utility that can download files from the http and https protocols, not only that, wget can also be run with proxies running on ports 80 and 443. The wget utility is non-interactive, meaning it can function in the background, which allows features This can be used by users without having to log in to a server.

In this tutorial, we'll cover the basics of using the Wget command to download files from the web, as well as some advanced options for power users. Whether you are a beginner or an experienced Linux/Unix user, this guide will get you up and running with Wget in no time. In this article the author implements the use of wget on the FreeBSD 13.2 Stable machine.


Article Contents


1. Installing wget on FreeBSD

To use wget on FreeBSD, you must install it first. On FreeBSD wget can be installed in 2 ways, with ports and packet pkg. The following is how to install wget on a FreeBSD system.

root@ns1:~ # cd /usr/ports/ftp/wget
root@ns1:/usr/ports/ftp/wget #
make install clean

Wget installation with pkg package.

root@ns1:~ # pkg install ftp/wget
root@ns1:~ #
pkg install wget


2. Basic wget Command Line Script

The basic syntax of the Wget command in FreeBSD is quite simple. Here we will demonstrate how to download files from a website. Below is the basic script used to download the file.

wget [options] [URL]

The "options" option is a flag in wget which is used to change the function of wget itself, while the "url" option is the link address or url on the website where we will download the file. For example, if you want to download a file named "example.txt" from a website with the URL "http://unixexplore.com", you can use the following command.

root@ns1:~ # wget http://unixexplore.com/example.txt

The above script will download a file named "example.txt" and save it in the /root folder. Why is it stored in the /root folder? Please pay attention when executing the wget command above, you are active in the /root folder. But when you execute the script above and you are active in the /usr/home folder, the "example.txt" file will be saved in the /usr/home folder.


2. How to Download Files With wget

Single File Download

In practice the wget utility is very simple in downloading one file and saving it to the current working directory. This command also shows the file size, download time, and download progress, as shown below.

root@ns1:/usr/home # wget https://www.electrical-forensics.com/Linux/unbound_pdf/unbound_Pi-hole_documentation.pdf
--2023-07-28 19:55:38-- https://www.electrical-forensics.com/Linux/unbound_pdf/unbound_Pi-hole_documentation.pdf
Resolving www.electrical-forensics.com (www.electrical-forensics.com)... 108.167.140.94
Connecting to www.electrical-forensics.com (www.electrical-forensics.com)|108.167.140.94|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 276916 (270K) [application/pdf]
Saving to: ‘unbound_Pi-hole_documentation.pdf’

unbound_Pi-hole_documentation.pdf 100%[========================================================================================>] 270.43K 159KB/s in 1.7s

2023-07-28 19:55:42 (159 KB/s) - ‘unbound_Pi-hole_documentation.pdf’ saved [276916/276916]

The script above will download the unbound_Pi-hole_documentation.pdf file and save it in the /usr/home folder. This method of downloading files is often called "single file download".


Multiple file download

Why is there the term "single file download", because the wget utility can be used to download files by "multiple file download", here's how.

root@ns1:/usr/home # wget https://www.electrical-forensics.com/Linux/unbound_pdf/unbound_Pi-hole_documentation.pdf wget https://www.bortzmeyer.org/unbound.pdf

The script above will download 2 files at once, namely the unbound.pdf and unbound_Pi-hole_documentation.pdf files.


Save the download results with a special name

Apart from the capabilities above, the wget utility can also be used to download files and save them under another name. Below is a script to download the unbound.pdf file and save it with a file called unbound_dns_server.pdf.

root@ns1:/usr/home # wget https://www.bortzmeyer.org/unbound.pdf -O unbound_dns_server.pdf

The -O option in the script above will change the unbound.pdf file to unbound_dns_server.pdf


3. How to Download Files Partially

Sometimes downloading fails due to large file size, or network disconnection. To avoid this, use the "-c" command line option with the wget command. By using “-c” option you can resume the download, so I suggest you whenever downloading a large file use “-c” to support resume to download the file as shown in the script below.

root@ns1:~ # wget -c https://download.freebsd.org/ftp/releases/ISO-IMAGES/13.2/FreeBSD-13.2-RELEASE-amd64-disc1.iso
--2023-07-28 20:23:55-- https://download.freebsd.org/ftp/releases/ISO-IMAGES/13.2/FreeBSD-13.2-RELEASE-amd64-disc1.iso
Resolving download.freebsd.org (download.freebsd.org)... 203.80.16.151, 2404:a8:3ff::15:0
Connecting to download.freebsd.org (download.freebsd.org)|203.80.16.151|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1072607232 (1023M) [application/octet-stream]
Saving to: ‘FreeBSD-13.2-RELEASE-amd64-disc1.iso’

FreeBSD-13.2-RELEASE-amd64-disc1.iso 0%[ ] 3.59M 1012KB/s eta 19m 40s^C


With the "-c" option, when the download is in progress and suddenly the internet is cut off, you can continue it again, without worrying about the file being corrupted.

Because the file size is too large and it takes quite a long time to complete the download, and you will be doing other work with FreeBSD, the solution is to add the "-b" option to the script above, so that the script will change to.

root@ns1:~ # wget -b -c https://download.freebsd.org/ftp/releases/ISO-IMAGES/13.2/FreeBSD-13.2-RELEASE-amd64-disc1.iso


The "-b" option above will run wget to send the process to the background immediately after starting the download.

The advantage of wget is that it can not only be run in the background daemon, the wget utility can also limit download speeds. Add the --limit-rate option to limit the download speed. You can use the --limit-rate option if your internet speed is low and you are worried that it could drain your internet bandwidth. The following is an example of downloading a file at 100k speed.

root@ns1:~ # wget -c --limit-rate=100k https://download.freebsd.org/ftp/releases/ISO-IMAGES/13.2/FreeBSD-13.2-RELEASE-amd64-disc1.iso


In conclusion, the Wget command is a powerful utility that allows you to download files from web sites. Once you install it, you can use its basic syntax to download files or explore its many options to customize your downloads.

The different options available with the Wget command include limiting download speed, resuming interrupted downloads, downloading only certain file types, mirroring websites, and recursively downloading from websites. With these options at your disposal, you can easily manage your downloads and maximize your bandwidth.
Iwan Setiawan

I Like Adventure: Mahameru Mount, Rinjani Mount I Like Writer FreeBSD

Post a Comment

Previous Post Next Post