假设目录
http://www.example.com/content/media/images/vacation_photos
包含许多子目录的链接:
/sweden
/egypt
/canada
每个文件都包含一堆 JPEG,我想将它们全部下载到我的本地文件夹中:
/home/jack/VacationPhotos
这样我就可以把所有内容都放到目录中
/home/jack/VacationPhotos/sweden
/home/jack/VacationPhotos/egypt
/home/jack/VacationPhotos/canada
问题是,如果我给 wget 该 URL,应用-r
(递归)选项和-P /home/jack/VacationPhotos
选项,它会下载所有内容到
/home/jack/VacationPhotos/content/media/images/vacation_photos/sweden
等等,而不是我想要的结构。在 wget 中可以实现这种行为吗?
答案1
查看中的-nH
and选项。来自手册页:--cut-dirs
wget
--cut-dirs=number
Ignore number directory components. This is useful for getting a fine-grained control over the directory where recursive retrieval will be saved.
Take, for example, the directory at ftp://ftp.xemacs.org/pub/xemacs/. If you retrieve it with -r, it will be saved locally under ftp.xemacs.org/pub/xemacs/. While the -nH option can
remove the ftp.xemacs.org/ part, you are still stuck with pub/xemacs. This is where --cut-dirs comes in handy; it makes Wget not "see" number remote directory components. Here are
several examples of how --cut-dirs option works.
No options -> ftp.xemacs.org/pub/xemacs/
-nH -> pub/xemacs/
-nH --cut-dirs=1 -> xemacs/
-nH --cut-dirs=2 -> .
--cut-dirs=1 -> ftp.xemacs.org/xemacs/
...
If you just want to get rid of the directory structure, this option is similar to a combination of -nd and -P. However, unlike -nd, --cut-dirs does not lose with subdirectories---for
instance, with -nH --cut-dirs=1, a beta/ subdirectory will be placed to xemacs/beta, as one would expect.