Skip to content

Wget – Download files to Specific Directory

On this page

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.

Rahul

Rahul Kumar is the founder and chief editor of TecAdmin.net. A Red Hat Certified Engineer (RHCE), he has worked in IT since 2009, with hands-on experience in Linux system administration, DevOps, web hosting, cloud platforms and automation. He started TecAdmin in 2013 to share practical, step-by-step guides, and leads its editorial work with one aim: making technical learning clear and useful for sysadmins, developers and beginners alike.

Leave a Reply

Your email address will not be published. Required fields are marked *


Back to top