我使用 wget 下载文件夹内的所有文件,并使用 -r 和 -np 选项。但是这也会下载前面的文件夹,而我并不需要。
例如:
wget -r -np ftp://user:[email protected]/articles/artist/images/
这将下载“图像”中的所有文件(这很好),然后还会下载文件夹文章,艺术家和图片(这很糟糕)。什么选项可以解决这个问题?
答案1
我认为您要找的是--cut-dirs
选项。与 (no hostname) 选项结合使用-nH
,您可以准确指定要在本地输出中显示的目录级别。例如,我有一个 .pkg 下载,我想将其写入我的本地目录,并且我不希望包含所有父树,只包含子目录。在这种情况下,我的起点只是获取 .pkg 名称,因为父目录向下 5 级:
wget -np -nH --cut-dirs 5 -r http://www.myhost.org/pub/downloads/My_Drivers/OS_10_5_x/Letter_Format/driver_C123_105.pkg
然后,您将在当前目录中看到名称 driver_C123_105.pkg。
% ls -lt | head
drwxr-xr-x 12 rob rob 408 Feb 22 12:54 driver_C123_105.pkg
-rw-------@ 1 rob rob 0 Feb 16 15:59 1kPSXcUj.pdf.part
-rw-------@ 1 rob rob 842 Feb 3 14:47 WcUuL69s.jnlp.part
[...ETC...]
% find driver_C123_105.pkg
driver_C123_105.pkg
driver_C123_105.pkg/Contents
driver_C123_105.pkg/Contents/Archive.bom
driver_C123_105.pkg/Contents/Archive.pax.gz
driver_C123_105.pkg/Contents/index.html
driver_C123_105.pkg/Contents/index.html?C=D;O=A
driver_C123_105.pkg/Contents/index.html?C=D;O=D
driver_C123_105.pkg/Contents/index.html?C=M;O=A
driver_C123_105.pkg/Contents/index.html?C=M;O=D
driver_C123_105.pkg/Contents/index.html?C=N;O=A
driver_C123_105.pkg/Contents/index.html?C=N;O=D
driver_C123_105.pkg/Contents/index.html?C=S;O=A
driver_C123_105.pkg/Contents/index.html?C=S;O=D
driver_C123_105.pkg/Contents/Info.plist
driver_C123_105.pkg/Contents/PkgInfo
driver_C123_105.pkg/Contents/Resources
driver_C123_105.pkg/Contents/Resources/background.jpg
[.....ETC....]
您可以使用该选项将此输出定向到其他地方-P
。
答案2
-Option--no-parent
就是您要找的。
答案3
你可能在找这个:
wget -r -np -nd ftp://user:[email protected]/articles/artist/images/
-nd 开关是 --no-directories 的缩写。
答案4
从man wget
:
-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.