wget没办法直接限制下载文件大小,而curl有这个功能,所以可以用curl来做文件下载
–max-filesize 9999 文件要小于9999 bytes, 文件大于此致会返回63错误,而不下载文件
wangxh@mac : ~$ curl 'http://www.baidu.com/img/10.23_112a036972a74bbcb84b8957316c8aa3.gif' --max-filesize 9999 -O -v * About to connect() to www.baidu.com port 80 (#0) * Trying 119.75.218.70... % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* connected * Connected to www.baidu.com (119.75.218.70) port 80 (#0) > GET /img/10.23_112a036972a74bbcb84b8957316c8aa3.gif HTTP/1.1 > User-Agent: curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8r zlib/1.2.5 > Host: www.baidu.com > Accept: */* > < HTTP/1.1 200 OK < Date: Tue, 23 Oct 2012 14:45:03 GMT < Server: Apache < P3P: CP=" OTI DSP COR IVA OUR IND COM " < Set-Cookie: BAIDUID=E8A14636EF42D5B73AB96A6B8E7F2D99:FG=1; expires=Wed, 23-Oct-13 14:45:03 GMT; max-age=31536000; path=/; domain=.baidu.com; version=1 < Last-Modified: Fri, 19 Oct 2012 08:31:06 GMT < ETag: "3333-4cc65532c0680" < Accept-Ranges: bytes * Maximum file size exceeded 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 * Closing connection #0 curl: (63) Maximum file size exceeded 文件大于这个限制即可成功
...