How to Set Custom Directory Prefix in Wget on Ubuntu
This guide explains how to specify a custom directory prefix when downloading files using wget on Ubuntu. You will learn the specific command-line flag required to direct downloads to a chosen folder structure without changing your current working directory. Follow the steps below to manage your downloaded content efficiently.
Use the -P Option
To specify a custom directory prefix, use the -P or
--directory-prefix flag followed by your desired path. This
tells wget to save the file inside that directory while maintaining the
original filename.
The basic syntax is:
wget -P /path/to/directory [URL]Practical Example
If you want to download a file into a folder named
backups located in your home directory, run the following
command:
wget -P ~/backups https://example.com/file.zipIf the backups directory does not exist, wget will
automatically create it before saving the file.
Combining with Other Options
You can combine the directory prefix with other common wget options.
For instance, to continue a partial download while specifying a
directory, use the -c flag alongside -P:
wget -c -P ~/downloads https://example.com/large-file.isoThis ensures your files are organized immediately upon download without requiring manual movement later.