当前位置:   article > 正文

Linux系统中wget命令用法详解_linux wget

linux wget

1、wget用法介绍

wget 用于从网络上下载文件。 它支持HTTP, HTTPS, FTP协议,以及通过HTTP代理进行检索。

可以通过 man wget 或者 wget --help 查看完整的选项列表。

  1. dgw@dgw-virtual-machine:~/Desktop/Study$ wget --help
  2. GNU Wget 1.21.2, a non-interactive network retriever.
  3. Usage: wget [OPTION]... [URL]...
  4. Mandatory arguments to long options are mandatory for short options too.
  5. Startup:
  6. -V, --version display the version of Wget and exit
  7. -h, --help print this help
  8. -b, --background go to background after startup
  9. -e, --execute=COMMAND execute a `.wgetrc'-style command
  10. Logging and input file:
  11. -o, --output-file=FILE log messages to FILE
  12. -a, --append-output=FILE append messages to FILE
  13. -d, --debug print lots of debugging information
  14. -q, --quiet quiet (no output)
  15. -v, --verbose be verbose (this is the default)
  16. -nv, --no-verbose turn off verboseness, without being quiet
  17. --report-speed=TYPE output bandwidth as TYPE. TYPE can be bits
  18. -i, --input-file=FILE download URLs found in local or external FILE
  19. -F, --force-html treat input file as HTML
  20. -B, --base=URL resolves HTML input-file links (-i -F)
  21. relative to URL
  22. --config=FILE specify config file to use
  23. --no-config do not read any config file
  24. --rejected-log=FILE log reasons for URL rejection to FILE
  25. Download:
  26. -t, --tries=NUMBER set number of retries to NUMBER (0 unlimits)
  27. --retry-connrefused retry even if connection is refused
  28. --retry-on-http-error=ERRORS comma-separated list of HTTP errors to retry
  29. -O, --output-document=FILE write documents to FILE
  30. -nc, --no-clobber skip downloads that would download to
  31. existing files (overwriting them)
  32. --no-netrc don't try to obtain credentials from .netrc
  33. -c, --continue resume getting a partially-downloaded file
  34. --start-pos=OFFSET start downloading from zero-based position OFFSET
  35. --progress=TYPE select progress gauge type
  36. --show-progress display the progress bar in any verbosity mode
  37. -N, --timestamping don't re-retrieve files unless newer than
  38. local
  39. --no-if-modified-since don't use conditional if-modified-since get
  40. requests in timestamping mode
  41. --no-use-server-timestamps don't set the local file's timestamp by
  42. the one on the server
  43. -S, --server-response print server response
  44. --spider don't download anything
  45. -T, --timeout=SECONDS set all timeout values to SECONDS
  46. --dns-timeout=SECS set the DNS lookup timeout to SECS
  47. --connect-timeout=SECS set the connect timeout to SECS
  48. --read-timeout=SECS set the read timeout to SECS
  49. -w, --wait=SECONDS wait SECONDS between retrievals
  50. (applies if more then 1 URL is to be retrieved)
  51. --waitretry=SECONDS wait 1..SECONDS between retries of a retrieval
  52. (applies if more then 1 URL is to be retrieved)
  53. --random-wait wait from 0.5*WAIT...1.5*WAIT secs between retrievals
  54. (applies if more then 1 URL is to be retrieved)
  55. --no-proxy explicitly turn off proxy
  56. -Q, --quota=NUMBER set retrieval quota to NUMBER
  57. --bind-address=ADDRESS bind to ADDRESS (hostname or IP) on local host
  58. --limit-rate=RATE limit download rate to RATE
  59. --no-dns-cache disable caching DNS lookups
  60. --restrict-file-names=OS restrict chars in file names to ones OS allows
  61. --ignore-case ignore case when matching files/directories
  62. -4, --inet4-only connect only to IPv4 addresses
  63. -6, --inet6-only connect only to IPv6 addresses
  64. --prefer-family=FAMILY connect first to addresses of specified family,
  65. one of IPv6, IPv4, or none
  66. --user=USER set both ftp and http user to USER
  67. --password=PASS set both ftp and http password to PASS
  68. --ask-password prompt for passwords
  69. --use-askpass=COMMAND specify credential handler for requesting
  70. username and password. If no COMMAND is
  71. specified the WGET_ASKPASS or the SSH_ASKPASS
  72. environment variable is used.
  73. --no-iri turn off IRI support
  74. --local-encoding=ENC use ENC as the local encoding for IRIs
  75. --remote-encoding=ENC use ENC as the default remote encoding
  76. --unlink remove file before clobber
  77. --xattr turn on storage of metadata in extended file attributes
  78. Directories:
  79. -nd, --no-directories don't create directories
  80. -x, --force-directories force creation of directories
  81. -nH, --no-host-directories don't create host directories
  82. --protocol-directories use protocol name in directories
  83. -P, --directory-prefix=PREFIX save files to PREFIX/..
  84. --cut-dirs=NUMBER ignore NUMBER remote directory components
  85. HTTP options:
  86. --http-user=USER set http user to USER
  87. --http-password=PASS set http password to PASS
  88. --no-cache disallow server-cached data
  89. --default-page=NAME change the default page name (normally
  90. this is 'index.html'.)
  91. -E, --adjust-extension save HTML/CSS documents with proper extensions
  92. --ignore-length ignore 'Content-Length' header field
  93. --header=STRING insert STRING among the headers
  94. --compression=TYPE choose compression, one of auto, gzip and none. (default: none)
  95. --max-redirect maximum redirections allowed per page
  96. --proxy-user=USER set USER as proxy username
  97. --proxy-password=PASS set PASS as proxy password
  98. --referer=URL include 'Referer: URL' header in HTTP request
  99. --save-headers save the HTTP headers to file
  100. -U, --user-agent=AGENT identify as AGENT instead of Wget/VERSION
  101. --no-http-keep-alive disable HTTP keep-alive (persistent connections)
  102. --no-cookies don't use cookies
  103. --load-cookies=FILE load cookies from FILE before session
  104. --save-cookies=FILE save cookies to FILE after session
  105. --keep-session-cookies load and save session (non-permanent) cookies
  106. --post-data=STRING use the POST method; send STRING as the data
  107. --post-file=FILE use the POST method; send contents of FILE
  108. --method=HTTPMethod use method "HTTPMethod" in the request
  109. --body-data=STRING send STRING as data. --method MUST be set
  110. --body-file=FILE send contents of FILE. --method MUST be set
  111. --content-disposition honor the Content-Disposition header when
  112. choosing local file names (EXPERIMENTAL)
  113. --content-on-error output the received content on server errors
  114. --auth-no-challenge send Basic HTTP authentication information
  115. without first waiting for the server's
  116. challenge
  117. HTTPS (SSL/TLS) options:
  118. --secure-protocol=PR choose secure protocol, one of auto, SSLv2,
  119. SSLv3, TLSv1, TLSv1_1, TLSv1_2 and PFS
  120. --https-only only follow secure HTTPS links
  121. --no-check-certificate don't validate the server's certificate
  122. --certificate=FILE client certificate file
  123. --certificate-type=TYPE client certificate type, PEM or DER
  124. --private-key=FILE private key file
  125. --private-key-type=TYPE private key type, PEM or DER
  126. --ca-certificate=FILE file with the bundle of CAs
  127. --ca-directory=DIR directory where hash list of CAs is stored
  128. --crl-file=FILE file with bundle of CRLs
  129. --pinnedpubkey=FILE/HASHES Public key (PEM/DER) file, or any number
  130. of base64 encoded sha256 hashes preceded by
  131. 'sha256//' and separated by ';', to verify
  132. peer against
  133. --random-file=FILE file with random data for seeding the SSL PRNG
  134. --ciphers=STR Set the priority string (GnuTLS) or cipher list string (OpenSSL) directly.
  135. Use with care. This option overrides --secure-protocol.
  136. The format and syntax of this string depend on the specific SSL/TLS engine.
  137. HSTS options:
  138. --no-hsts disable HSTS
  139. --hsts-file path of HSTS database (will override default)
  140. FTP options:
  141. --ftp-user=USER set ftp user to USER
  142. --ftp-password=PASS set ftp password to PASS
  143. --no-remove-listing don't remove '.listing' files
  144. --no-glob turn off FTP file name globbing
  145. --no-passive-ftp disable the "passive" transfer mode
  146. --preserve-permissions preserve remote file permissions
  147. --retr-symlinks when recursing, get linked-to files (not dir)
  148. FTPS options:
  149. --ftps-implicit use implicit FTPS (default port is 990)
  150. --ftps-resume-ssl resume the SSL/TLS session started in the control connection when
  151. opening a data connection
  152. --ftps-clear-data-connection cipher the control channel only; all the data will be in plaintext
  153. --ftps-fallback-to-ftp fall back to FTP if FTPS is not supported in the target server
  154. WARC options:
  155. --warc-file=FILENAME save request/response data to a .warc.gz file
  156. --warc-header=STRING insert STRING into the warcinfo record
  157. --warc-max-size=NUMBER set maximum size of WARC files to NUMBER
  158. --warc-cdx write CDX index files
  159. --warc-dedup=FILENAME do not store records listed in this CDX file
  160. --no-warc-compression do not compress WARC files with GZIP
  161. --no-warc-digests do not calculate SHA1 digests
  162. --no-warc-keep-log do not store the log file in a WARC record
  163. --warc-tempdir=DIRECTORY location for temporary files created by the
  164. WARC writer
  165. Recursive download:
  166. -r, --recursive specify recursive download
  167. -l, --level=NUMBER maximum recursion depth (inf or 0 for infinite)
  168. --delete-after delete files locally after downloading them
  169. -k, --convert-links make links in downloaded HTML or CSS point to
  170. local files
  171. --convert-file-only convert the file part of the URLs only (usually known as the basename)
  172. --backups=N before writing file X, rotate up to N backup files
  173. -K, --backup-converted before converting file X, back up as X.orig
  174. -m, --mirror shortcut for -N -r -l inf --no-remove-listing
  175. -p, --page-requisites get all images, etc. needed to display HTML page
  176. --strict-comments turn on strict (SGML) handling of HTML comments
  177. Recursive accept/reject:
  178. -A, --accept=LIST comma-separated list of accepted extensions
  179. -R, --reject=LIST comma-separated list of rejected extensions
  180. --accept-regex=REGEX regex matching accepted URLs
  181. --reject-regex=REGEX regex matching rejected URLs
  182. --regex-type=TYPE regex type (posix|pcre)
  183. -D, --domains=LIST comma-separated list of accepted domains
  184. --exclude-domains=LIST comma-separated list of rejected domains
  185. --follow-ftp follow FTP links from HTML documents
  186. --follow-tags=LIST comma-separated list of followed HTML tags
  187. --ignore-tags=LIST comma-separated list of ignored HTML tags
  188. -H, --span-hosts go to foreign hosts when recursive
  189. -L, --relative follow relative links only
  190. -I, --include-directories=LIST list of allowed directories
  191. --trust-server-names use the name specified by the redirection
  192. URL's last component
  193. -X, --exclude-directories=LIST list of excluded directories
  194. -np, --no-parent don't ascend to the parent directory
  195. Email bug reports, questions, discussions to <bug-wget@gnu.org>
  196. and/or open issues at https://savannah.gnu.org/bugs/?func=additem&group=wget.

2、wget基本用法

2.1 下载单个文件

wget http://example.com/file.iso wget https://down.xxjsq3.com/xx48.exe

2.2 下载并保存为不同的文件名

wget -O new_xx48.exe https://down.xxjsq3.com/xx48.exe

2.3 断点续传

如果由于某种原因下载被中断,你可以使用 -c 选项继续进行下载。

  1. wget -c https://down.xxjsq3.com/xx48.exe
  2. wget -O new_xx48_c.exe -c https://down.xxjsq3.com/xx48.exe

2.4 下载多个文件

你可以创建一个文本文件,列出所有要下载的URL,然后使用 -i 选项进行下载。

urls.txt:

  1. https://down.xxjsq3.com/xx48.exe
  2. https://skk1t.pgjsq1.com:43622/pg48.exe

2.5 限制下载速度

你可以使用 --limit-rate 选项来限制下载速度。

wget --limit-rate=200k https://down.xxjsq3.com/xx48.exe

2.6 下载整个网站

使用 -r (或者 --recursive)选项可以下载整个网站。

wget -r http://example.com/

2.7 在后台下载

-b 选项可以让 wget 在后台下载文件。日志文件很全。

wget -b https://down.xxjsq3.com/xx48.exe

2.8 设置最大深度

-l 选项可以设置递归下载时的最大深度。

wget -r -l1 http://example.com/

参考博文:

wget入门-CSDN博客

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/酷酷是懒虫/article/detail/995368?site
推荐阅读
相关标签
  

闽ICP备14008679号