我如何指定wget
应下载所有文件的目录?为了了解情况,我目前正在运行脚本:
wget -r --no-parent --reject "index.html*" http://water.weather.gov/precip/p_download_new/2010/01/01/
问题是文件存储在中water.weather.gov/precip/p_download_new/2010/01/01/
,我想将所有文件存储到中2010/01/01
,我该如何指定?
答案1
你可以这样使用它
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/
答案2
您需要添加-P /your/chosen/directory
到您的命令中。
答案3
添加参数-P
:
wget -P "2010/01/01" -nd -r --no-parent --reject "index.html*" http://water.weather.gov/precip/p_download_new/2010/01/01/
而且更加通用。使用此版本,可以自动确定输出文件夹:
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"
从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).