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: 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: 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.