Wget is a free command-line utility for downloading files from the remote server. It supports HTTP, HTTPS, and FTP protocols, as well as follows the HTTP proxies servers.
The default wget download files under the current working directory. In this tutorial, we will describe you to how to download files to a specific directory using wget.
Using wget -O
Option
Use -O
or --output-document=FILE
option will truncate FILE immediately, and all downloaded content will be written to FILE. Here the wget -O FILE http://path
is intended to work like wget -O - http://path > FILE
;
For example:
wget -O /tmp/Ubuntu.iso https://releases.ubuntu.com/20.04/ubuntu-20.04-desktop-amd64.iso
The above command will download the remote ISO file with the Wget command and save it as /tmp/Ubuntu.iso in the local system. No matter what is the current working directory.
Using wget -P
Option
Alternatively, Use -P
or --directory-prefix=PREFIX
. Here the PREFIX is a directory where all other files and subdirectories will be saved to. The default download directory is “.” the current directory.
For example:
wget -P /tmp https://releases.ubuntu.com/20.04/ubuntu-20.04-desktop-amd64.iso
The above command will download the iso file under the /tmp
directory.
Conclusion
In this guide, you have learned two methods to download files to a specified directory using the Wget command.