1

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 '15 at 15:39
1

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/
1

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 '15 at 15:19
1

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
   --directory-prefix=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).

-nd
   --no-directories
       Do not create a hierarchy of directories when retrieving
       recursively.
       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).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.