wget:获取匹配正则表达式的文件

Zho*_*Jin 9 unix linux ftp wget download

根据wget的手册页,--acccept-regex是当我需要有选择地传输名称与某个正则表达式匹配的文件时使用的参数。但是,我不确定如何使用--accept-regex

假设我想在 IMDB 数据目录ftp://ftp.fu-berlin 中获取文件diffs-000107.tar.gz、diffs-000114.tar.gz、diffs-000121.tar.gz、diffs- 000128.tar.gz .de/pub/misc/movies/database/diffs/。“ diffs\-0001[0-9]{2}\.tar\.gz ”似乎是描述文件名的好正则表达式。

但是,当执行以下 wget 命令时

wget -r --accept-regex='diffs\-0001[0-9]{2}\.tar\.gz' ftp://ftp.fu-berlin.de/pub/misc/movies/database/diffs/
Run Code Online (Sandbox Code Playgroud)

wget 不加选择地获取ftp://ftp.fu-berlin.de/pub/misc/movies/database/diffs/目录中的所有文件。

我想知道是否有人可以告诉我可能做错了什么?

Yuc*_*ang 5

注意--accept-regex是完整的 URL。但是我们的目标是一些特定的文件。所以我们将使用-A.

例如,

wget -r -np -nH -A "IMG[012][0-9].jpg" http://x.com/y/z/ 
Run Code Online (Sandbox Code Playgroud)

将从 URL 中将所有文件从 IMG00.jpg 下载到 IMG29.jpg。

请注意,匹配模式包含类似 shell 的通配符,例如“books”或“zelazny196[0-9]*”。

参考:wget 手册:https ://www.gnu.org/software/wget/manual/wget.html 正则表达式:https : //regexone.com/


Bas*_*tch 1

我正在wget手册页中阅读:

\n\n
\n
  --accept-regex urlregex\n  --reject-regex urlregex\n       Specify a regular expression to accept or reject the complete URL.\n
Run Code Online (Sandbox Code Playgroud)\n
\n\n

并注意到它提到了完整的URL(例如类似的东西
ftp://ftp.fu-berlin.de/pub/misc/movies/database/diffs/diffs-000121.tar.gz

\n\n

所以我建议(没有尝试过)使用
\n --accept-regex=\'.*diffs\\-0001[0-9][0-9]\\.tar\\.gz\'

\n\n

(也许--regex-type也给出适当的)

\n\n

顺便说一句,对于此类任务,我还会考虑使用某种脚本语言 \xc3\xa0 la Python (或使用libcurlcurl

\n