我有一个web目录,我存储一些配置文件。我想使用wget将这些文件拉下来并保持它们当前的结构。例如,远程目录看起来像:
http://mysite.com/configs/.vim/
.vim包含多个文件和目录。我想用wget在客户端复制它。似乎无法找到正确的wget标志组合来完成这项工作。什么好主意吗?
我有一个web目录,我存储一些配置文件。我想使用wget将这些文件拉下来并保持它们当前的结构。例如,远程目录看起来像:
http://mysite.com/configs/.vim/
.vim包含多个文件和目录。我想用wget在客户端复制它。似乎无法找到正确的wget标志组合来完成这项工作。什么好主意吗?
当前回答
你所需要的是两个标志,一个是“-r”表示递归,另一个是“——no-parent”(或-np),以便不进入'。和“..”. 是这样的:
Wget -r——no-parent http://example.com/configs/.vim/
就是这样。它将下载到以下本地树:./example.com/configs/.vim。 然而,如果你不想要前两个目录,那么使用额外的标志——cut-dirs=2,就像之前的回复中建议的那样:
Wget -r——no-parent——cut-dirs=2 http://example.com/configs/.vim/
它只会把你的文件树下载到。/.vim/
事实上,我从wget手册中得到了这个答案的第一行,他们在4.3节的末尾有一个非常干净的例子。
其他回答
递归下载一个目录,该目录拒绝index.html*文件,下载时不包含主机名、父目录和整个目录结构:
wget -r -nH --cut-dirs=2 --no-parent --reject="index.html*" http://mysite.com/dir1/dir2/data
wget -r http://mysite.com/configs/.vim/
对我有用。
也许你有一个。wgetrc干扰它?
递归wget忽略机器人(用于网站)
wget -e robots=off -r -np --page-requisites --convert-links 'http://example.com/folder/'
-e robots=off使它忽略该域的robots.txt
-r使它递归
-np = no parent,所以它不会跟随链接到父文件夹
对于其他有类似问题的人。Wget遵循robots.txt,这可能不允许您抓取站点。不用担心,你可以把它关掉:
wget -e robots=off http://www.example.com/
http://www.gnu.org/software/wget/manual/html_node/Robot-Exclusion.html
下面的选项似乎是处理递归下载时的完美组合:
wget -nd -n -P -P /dest/dir -充值http://url/dir1 dir2
为方便起见,手册页中的相关片段:
-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).
-np
--no-parent
Do not ever ascend to the parent directory when retrieving recursively. This is a useful option, since it guarantees that only the files below a certain hierarchy will be downloaded.