假设目录
http://www.example.com/content/media/images/vacation_photos
Run Code Online (Sandbox Code Playgroud)
包含指向许多子目录的链接:
/sweden
/egypt
/canada
Run Code Online (Sandbox Code Playgroud)
每个都包含一堆 JPEG,我想将它们全部下载到我的本地文件夹:
/home/jack/VacationPhotos
Run Code Online (Sandbox Code Playgroud)
所以我最终得到目录中的所有内容
/home/jack/VacationPhotos/sweden
/home/jack/VacationPhotos/egypt
/home/jack/VacationPhotos/canada
Run Code Online (Sandbox Code Playgroud)
问题是,如果我给 wget 那个 URL,应用-r(递归)选项和-P /home/jack/VacationPhotos选项,它会将所有内容下载到
/home/jack/VacationPhotos/content/media/images/vacation_photos/sweden
Run Code Online (Sandbox Code Playgroud)
等等,而不是我想要的结构。是否有可能在 wget 中获得这种行为?
查看中的-nH和选项。从联机帮助页:--cut-dirswget
--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.
Run Code Online (Sandbox Code Playgroud)