How can I specify the directory that wget should download all files to? To get an idea I'm currently running the script:

wget -r --no-parent --reject "index.html*" http://water.weather.gov/precip/p_download_new/2010/01/01/

The problem is the files are stored in water.weather.gov/precip/p_download_new/2010/01/01/ , I'd like to store all files into just 2010/01/01 , how can I specify this?

  • I have a generic version for you click
    – A.B.
    Jun 12, 2015 at 15:39

3 Answers 3


you can use it likfe that

wget -r --no-parent -P /path-to-"2010/01/01"-directory -nd --reject "index.html*" http://water.weather.gov/precip/p_download_new/2010/01/01/

You need to add -P /your/chosen/directory to your command.

  • Thanks, I also found I needed to specify -nd so It grabs just the files and doesn't create the directories as well
    – Need4Sleep
    Jun 12, 2015 at 15:19

Add the parameter -P:

wget -P "2010/01/01" -nd -r --no-parent --reject "index.html*" http://water.weather.gov/precip/p_download_new/2010/01/01/

And more generic. With this version, the output folder is determined automatically:

URL="http://water.weather.gov/precip/p_download_new/2010/01/01/"; wget -P "$(awk -F'/' '{ print $(NF-3),$(NF-2),$(NF-1)}' OFS="/" <<<$URL)" -nd -r --no-parent --reject "index.html*" "$URL"

from man wget

-P prefix
       Set directory prefix to prefix. 
       The directory prefix is the directory where all other files and
       subdirectories will be saved to, i.e. the top of the retrieval
       tree.  The default is . (the current directory).

       Do not create a hierarchy of directories when retrieving
       With this option turned on, all files will get saved to the
       current directory, without clobbering (if a name shows up more
       than once, the
       filenames will get extensions .n).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .