wget 可以创建与链接相同的目录结构吗?

问题描述

我有几个来自不同网站的 pdf 链接。 例子:

www.example.com/excel/1.pdf

我如何获取链接,以便将 1.pdf 下载到 /example.com/excel/1/ 目录中。 wget 是否可以自动创建目录路径,而无需在 wget 命令中手动创建或定义该路径?

解决方法

是的,你可以。 你可以用开关 O 做想要的地址

wget -O /path/to/file.ext

也按命令 curl 做同样的事情只是代替 O Great from O 使用 small。最后,您必须以任何方式重复此操作,例如,如果您有数字命名并且数字只会增加,请使用简单或循环重复该命令

,

虽然另一个答案在技术上是正确的,但这并不是最好的做事方式。

Wget 可以使用 -x,--force-directories 选项完成 OP 正在寻找的工作。引用手册页:

   -x
   --force-directories
       The opposite of -nd---create a hierarchy of directories,even if one would not have been created otherwise.  E.g. wget -x http://fly.srk.fer.hr/robots.txt will save the
       downloaded file to fly.srk.fer.hr/robots.txt.

所以,您只需要:

wget -x www.example.com/excel/1.pdf