wget [option]... [URL]...
GNU wget
is a free utility for non-interactive download of files from the Web. It supports HTTP, HTTPS, and FTP protocols, as well as retrieval through HTTP proxies.
wget
is non-interactive, meaning that it can work in the background, while the user is not logged on. This allows you to start a retrieval and disconnect from the system, letting wget
finish the work. By contrast, most of the Web browsers require constant user’s presence, which can be a great hindrance when transferring a lot of data.
wget
can follow links in HTML, XHTML, and CSS pages, to create local versions of remote web sites, fully recreating the directory structure of the original site. This is sometimes referred to as "recursive downloading.. While doing that, wget
respects the Robot Exclusion Standard (/robots.txt). wget
can be instructed to convert the links in downloaded files to point at the local files, for offline viewing.
wget
has been designed for robustness over slow or unstable network connections; if a download fails due to a network problem, it will keep retrying until the whole file has been retrieved. If the server supports regetting, it will instruct the server to continue the download from where it left off.
wget
.wget
’s command-line options.wget
if it does not work properly. Your system administrator may have chosen to compile wget
without debug support, in which case -d will not work. Please note that compiling with debug support is always safe---wget
compiled with the debug support will not print any debug info unless requested with -d.wget
’s output.--base=url
on the command line. If the file is an external one, the document will be automatically treated as html if the Content-Type matches text/html. Furthermore, the file’s location will be implicitly used as base href if none was specified.wget
reads ../baz/b.html from the input file, it would be resolved to http://foo/baz/b.html.wget -O file http://foois intended to work like
wget -O - http://foo > file;
file will be truncated immediately, and all downloaded content will be written there. For this reason, -N (for timestamp-checking) is not supported in combination with -O: since file is always newly created, it will always have a very new timestamp. A warning will be issued if this combination is used.
Similarly, using -r or -p with -O may not work as you expect: wget
won’t just download the first file to file and then download the rest to their normal names: all downloaded content will be placed in file. This was disabled in version 1.11, but has been reinstated (with a warning) in 1.11.2, as there are some cases where this behavior can actually have some use. Note that a combination with -k is only permitted when downloading a single document, as in that case it will just convert all relative URIs to external ones; -k makes no sense for multiple URIs when they’re all being downloaded to a single file.
wget
’s behavior depends on a few options, including -nc. In certain cases, the local file will be clobbered, or overwritten, upon repeated download. In other cases it will be preserved.
wget
without -N, -nc, -r, or -p, downloading the same file in the same directory will result in the original copy of file being preserved and the second copy being named file.1. If that file is downloaded yet again, the third copy will be named file.2, and so on. (This is also the behavior with -nd, even if -r or -p are in effect.) When -nc is specified, this behavior is suppressed, and wget
will refuse to download newer copies of file. Therefore, ""no-clobber"" is actually a misnomer in this mode---it’s not clobbering that’s prevented (as the numeric suffixes were already preventing clobbering), but rather the multiple version saving that’s prevented.wget
with -r or -p, but without -N, -nd, or -nc, re-downloading a file will result in the new copy simply overwriting the old. Adding -nc will prevent this behavior, instead causing the original version to be preserved and any newer copies on the server to be ignored.wget
with -N, with or without -r or -p, the decision as to whether or not to download a newer copy of a file depends on the local and remote timestamp and size of the file. -nc may not be specified at the same time as -N.wget
, or by another program. For instance:
wget -c ftp://sunsite.doc.ic.ac.uk/ls-lR.Z
If there is a file named ls-lR.Z in the current directory, wget
will assume that it is the first portion of the remote file, and will ask the server to continue the retrieval from an offset equal to the length of the local file.
Note that you don’t need to specify this option if you just want the current invocation of wget
to retry downloading a file should the connection be lost midway through. This is the default behavior. -c only affects resumption of downloads started prior to this invocation of wget
, and whose local files are still sitting around.
Without -c, the previous example would just download the remote file to ls-lR.Z.1, leaving the truncated ls-lR.Z file alone.
Beginning with wget
1.7, if you use -c on a non-empty file, and it turns out that the server does not support continued downloading, wget
will refuse to start the download from scratch, which would effectively ruin existing contents. If you really want the download to start from scratch, remove the file.
Also beginning with wget
1.7, if you use -c on a file which is of equal size as the one on the server, wget
will refuse to download the file and print an explanatory message. The same happens when the file is smaller on the server than locally (presumably because it was changed on the server since your last download attempt)---because "continuing" is not meaningful, no download occurs.
On the other side of the coin, while using -c, any file that’s bigger on the server than locally will be considered an incomplete download and only "(length(remote) - length(local))" bytes will be downloaded and tacked onto the end of the local file. This behavior can be desirable in certain cases---for instance, you can use wget -c to download just the new portion that’s been appended to a data collection or log file.
However, if the file is bigger on the server because it’s been changed, as opposed to just appended to, you’ll end up with a garbled file. wget
has no way of verifying that the local file is really a valid prefix of the remote file. You need to be especially careful of this when using -c in conjunction with -r, since every file will be considered as an "incomplete download" candidate.
Another instance where you’ll get a garbled file if you try to use -c is if you have a lame HTTP proxy that inserts a "transfer interrupted" string into the local file. In the future a "rollback" option may be added to deal with this case.
Note that -c only works with FTP servers and with HTTP servers that support the "Range" header.
--progress=dot
to switch to the "dot" display. It traces the retrieval by printing dots on the screen, each dot representing a fixed amount of downloaded data. When using the dotted retrieval, you may also set the style by specifying the type as dot:style. Different styles assign different meaning to one dot. With the "default" style each dot represents 1K, there are ten dots in a cluster and 50 dots in a line. The "binary" style has a more "computer"-like orientation---8K dots, 16-dots clusters and 48 dots per line (which makes for 384K lines). The "mega" style is suitable for downloading very large files---each dot represents 64K retrieved, there are eight dots in a cluster, and 48 dots on each line (so each line contains 3M).--progress=bar:force
.wget
will behave as a Web spider, which means that it will not download the pages, just check that they are there. For example, you can use wget
to check your bookmarks:
wget --spider --force-html -i bookmarks.htmlThis feature needs much more work for
wget
to get close to the functionality of real web spiders.wget
can check for timeout and abort the operation if it takes too long. This prevents anomalies like hanging reads and infinite connects. The only timeout enabled by default is a 900-second read timeout. Setting a timeout to 0 disables it altogether. Unless you know what you are doing, it is best not to change the default timeout settings.--limit-rate=20k
will limit the retrieval rate to 20KB/s. This is useful when, for whatever reason, you don’t want wget
to consume the entire available bandwidth.--limit-rate=2.5k
is a legal value.wget
implements the limiting by sleeping the appropriate amount of time after a network read that took less time than specified by the rate. Eventually this strategy causes the TCP transfer to slow down to approximately the specified rate. However, it may take some time for this balance to be achieved, so don’t be surprised if limiting the rate doesn’t work well with very small files.wget
can wait long enough to reasonably expect the network error to be fixed before the retry. The waiting interval specified by this function is influenced by --random-wait, which see.wget
to wait between every retrieval, but only between retries of failed downloads, you can use this option. wget
will use linear backoff, waiting 1 second after the first failure on a given file, then waiting 2 seconds after the second failure on that file, up to the maximum number of seconds you specify. Therefore, a value of 10 will actually make wget
wait up to (1 + 2 + ... + 10) = 55 seconds per file. By default, wget
will assume a value of 10 seconds.wget
by looking for statistically significant similarities in the time between requests. This option causes the time between requests to vary between 0.5 and 1.5 * wait seconds, where wait was specified using the --wait option, in order to mask wget
’s presence from such analysis.wget -Q10k ftp://wuarchive.wustl.edu/ls-lR.gz
all of the ls-lR.gz will be downloaded. The same goes even when several URLs are specified on the command-line. However, quota is respected when retrieving either recursively, or from an input file. Thus you may safely type wget -Q2m -i sites
, download will be aborted when the quota is exceeded.
Setting quota to 0 or to inf unlimits the download quota.
wget
remembers the IP addresses it looked up from DNS so it doesn’t have to repeatedly contact the DNS server for the same (typically small) set of hosts it retrieves from. This cache exists in memory only; a new wget
run will contact DNS again.wget
. With this option wget
issues a new DNS lookup (more precisely, a new call to "gethostbyname" or "getaddrinfo") each time it makes a new connection. Please note that this option will not affect caching that might be performed by the resolving library or by an external caching layer, such as NSCD.wget
escapes the characters that are not valid or safe as part of file names on your operating system, as well as control characters that are typically unprintable. This option is useful for changing these defaults, perhaps because you are downloading to a non-native partition, or because you want to disable escaping of the control characters, or you want to further restrict characters to only those in the ASCII range of values.wget
escapes the character / and the control characters in the ranges 0--31 and 128--159. This is the default on Unix-like operating systems.wget
escapes the characters \, |, /, :, ?, ", *, <, >, and the control characters in the ranges 0--31 and 128--159. In addition to this, wget
in Windows mode uses + instead of : to separate host and port in local file names, and uses @ instead of ? to separate the query portion of the file name from the rest. Therefore, a URL that would be saved as www.xemacs.org:4300/search.pl?input=blah in Unix mode would be saved as www.xemacs.org+4300/[email protected]=blah in Windows mode. This mode is the default on Windows.wget
as "controls").wget
will only connect to IPv4 hosts, ignoring AAAA records in DNS, and refusing to connect to IPv6 addresses specified in URLs. Conversely, with --inet6-only or -6, wget
will only connect to IPv6 hosts and ignore A records and IPv4 addresses.wget
will use the address family specified by the host’s DNS record. If the DNS responds with both IPv4 and IPv6 addresses, wget
will try them in sequence until it finds one it can connect to. (Also see "--prefer-family" option described below.)wget
compiled without IPv6 support.wget
gives up on a URL when it is unable to connect to the site because failure to connect is taken as a sign that the server is not running at all and that retries would not help. This option is for mirroring unreliable sites whose servers tend to disappear for short periods of time.wget
to use encoding as the default system encoding. That affects how wget
converts URLs specified as arguments from locale to UTF-8 for IRI support. wget
use the function "nl_langinfo()" and then the "CHARSET" environment variable to get the locale. If it fails, ASCII is used. You can set the default local encoding using the "local_encoding" command in .wgetrc. That setting may be overridden from the command line.wget
to use encoding as the default remote server encoding. That affects how wget
converts URIs found in files from remote encoding to UTF-8 during a recursive fetch. This options is only useful for IRI support, for the interpretation of non-ASCII characters. For HTTP, remote encoding can be found in HTTP "Content-Type" header and in HTML "Content-Type http-equiv" meta tag. You can set the default encoding using the "remoteencoding" command in .wgetrc. That setting may be overridden from the command line.wget -x http://fly.srk.fer.hr/robots.txtwill save the downloaded file to fly.srk.fer.hr/robots.txt.
wget
with -r http://fly.srk.fer.hr/ will create a structure of directories beginning with fly.srk.fer.hr/. This option disables such behavior.wget -r http://hostwill save to http/host/... rather than just to host/.... /
wget
not "see" number remote directory components. Here are several examples of how --cut-dirs option works.
--cut-dirs=1
: xemacs--cut-dirs=2
: .--cut-dirs=1
-> ftp.xemacs.org/xemacs-nd
and -P
. However, unlike -nd
, --cut-dirs
does not lose with subdirectories---for instance, with -nH --cut-dirs=1
, a beta/ subdirectory will be placed to xemacs/beta, as one would expect.wget
can’t tell that the local X.html file corresponds to remote URL X (since it doesn’t yet know that the URL produces output of type text/html or application/xhtml+xml. To prevent this re-downloading, you must use -k and -K so that the original version of the file will be saved as X.orig.wget
will also ensure that any downloaded files of type text/css end in the suffix .css, and the option was renamed from --html-extension, to better reflect its new behavior. The old option name is still acceptable, but should now be considered deprecated. At some point in the future, this option may well be expanded to include suffixes for other types of content, including content types that are not parsed by wget
.wget
will encode them using either the "basic" (insecure), the "digest", or the Windows "NTLM" authentication scheme. Another way to specify username and password is in the URL itself. Either method reveals your password to anyone who bothers to run "ps". To prevent the passwords from being seen, store them in .wgetrc or .netrc, and make sure to protect those files from other users with "chmod". If the passwords are really important, do not leave them lying in those files either---edit the files and delete them after wget
has started the download.wget
asks the server to keep the connection open so that, when you download more than one document from the same server, they get transferred over the same TCP connection. This saves time and at the same time reduces the load on the server. This option is useful when, for some reason, persistent (keep-alive) connections don’t work for you, for example due to a server bug or due to the inability of server-side scripts to cope with the connections.wget
will send the remote server an appropriate directive (Pragma: no-cache) to get the file from the remote service, rather than returning the cached version. This is especially useful for retrieving and flushing out-of-date documents on proxy servers. Caching is allowed by default.wget
to send the same cookies your browser sends when communicating with the site. This is achieved by --load-cookies---simply point wget
to the location of the cookies.txt file, and it will send the same cookies your browser would send in the same situation. Different browsers keep textual cookie files in different locations:
wget
can use by using the File menu, Import and Export, Export Cookies. This has been tested with Internet Explorer 5; it is not guaranteed to work with earlier versions.wget
expects.wget
to send those cookies, bypassing the "official" cookie support:
wget --no-cookies --header "Cookie:= "
wget
runs are considered a single browser session as far as the site is concerned. Since the cookie file format does not normally carry session cookies, wget
marks them with an expiry timestamp of 0. wget
’s --load-cookies recognizes those as session cookies, but it might confuse other browsers. Also note that cookies so loaded will be treated as other session cookies, which means that if you want --save-cookies to preserve them again, you must use --keep-session-cookies again.wget
go wild, as it thinks not all the document was retrieved. You can spot this syndrome if wget
retries getting the same document again and again, each time claiming that the (otherwise normal) connection has closed on the very same byte.wget
will ignore the "Content-Length" header---as if it never existed.wget --header='Accept-Charset: iso-8859-2' --header='Accept-Language: hr' http://fly.srk.fer.hr/Specification of an empty string as the header value will clear all previous user-defined headers.
wget
1.10, this option can be used to override headers otherwise generated automatically. This example instructs wget
to connect to localhost, but to specify foo.bar in the "Host" header:
wget --header="Host: foo.bar" http://localhost/In versions of
wget
prior to 1.10 such use of --header caused sending of duplicate headers.wget
will encode them using the "basic" authentication scheme.wget
normally identifies as wget
/version, version being the current version number of wget
.wget
. Use of this option is discouraged, unless you really know what you are doing.--user-agent=""
instructs wget
not to send the "User-Agent" header in HTTP requests.wget
does not currently support "multipart/form-data" for transmitting POST data; only "application/x-www-form-urlencoded". Only one of --post-data and --post-file should be specified.wget
needs to know the size of the POST data in advance. Therefore the argument to "--post-file" must be a regular file; specifying a FIFO or something like /dev/stdin won’t work. It’s not quite clear how to work around this limitation inherent in HTTP/1.0. Although HTTP/1.1 introduces chunked transfer that doesn’t require knowing the request length in advance, a client can’t use chunked unless it knows it’s talking to an HTTP/1.1 server. And it can’t know that until it receives a response, which in turn requires the request to have been completed -- a chicken-and-egg problem.wget
is redirected after the POST request is completed, it will not send the POST data to the redirected URL. This is because URLs that process POST often respond with a redirection to a regular page, which does not desire or accept POST. It is not completely clear that this behavior is optimal; if it doesn’t work out, it might be changed in the future. This example shows how to log to a server using POST and then proceed to download the desired pages, presumably only accessible to authorized users:
# Log in to the server. This can be done only once. wget --save-cookies cookies.txt \ --post-data 'user=foo&password=bar' \ http://server.com/auth.php # Now grab the page or pages we care about. wget --load-cookies cookies.txt \ -p http://server.com/interesting/article.phpIf the server is using session cookies to track user authentication, the above will not work because --save-cookies will not save them (and neither will browsers) and the cookies.txt file will be empty. In that case use --keep-session-cookies along with --save-cookies to force saving of session cookies.
wget
will send Basic HTTP authentication information (plaintext username and password) for all requests, just like wget
1.10.2 and prior did by default. Use of this option is not recommended, and is intended only to support some few obscure servers, which never send HTTP authentication challenges, but accept unsolicited auth info, say, in addition to form-based authentication.To support encrypted HTTP (HTTPS) downloads, wget
must be compiled with an external SSL library, currently OpenSSL. If wget
is compiled without SSL support, none of these options are available.
wget
1.10, the default is to verify the server’s certificate against the recognized certificate authorities, breaking the SSL handshake and aborting the download if the verification fails. Although this provides more secure downloads, it does break interoperability with some sites that worked with previous wget
versions, particularly those using self-signed, expired, or otherwise invalid certificates. This option forces an "insecure" mode of operation that turns the certificate verification errors into warnings and allows you to proceed.wget
looks for CA certificates at the system-specified locations, chosen at OpenSSL installation time.wget
to fetch certificates on demand. Without this option wget
looks for CA certificates at the system-specified locations, chosen at OpenSSL installation time.wget
looks for random data in $RANDFILE or, if that is unset, in $HOME/.rnd. If none of those are available, it is likely that SSL encryption will not be usable. If you’re getting the "Could not seed OpenSSL PRNG; disabling SSL." error, you should provide random data using some of the methods described above.wget
has started the download.wget
writes to a known filename for this file, this is not a security hole in the scenario of a user making .listing a symbolic link to /etc/passwd or something and asking "root" to run wget
in his or her directory. Depending on the options used, either wget
will refuse to write to .listing, making the globbing/recursion/time-stamping operation fail, or the symbolic link will be deleted and replaced with the actual .listing file, or the listing will be written to a .listing.number file.wget
in a non-trusted user’s directory. A user could do something as simple as linking index.html to /etc/passwd and asking "root" to run wget
with -N or -r so the file will be overwritten.wget ftp://gnjilux.srk.fer.hr/*.msgBy default, globbing will be turned on if the URL contains a globbing character. This option may be used to turn globbing on or off permanently. You may have to quote the URL to protect it from being expanded by your shell. Globbing makes
wget
look for a directory listing, which is system-specific. This is why it currently works only with Unix FTP servers (and the ones emulating Unix "ls" output).wget
does not traverse symbolic links to directories to download them recursively, though this feature may be added in the future.--retr-symlinks=no
is specified, the linked-to file is not downloaded. Instead, a matching symbolic link is created on the local filesystem. The pointed-to file will not be retrieved unless this recursive retrieval would have encountered it separately and downloaded it anyway. This option poses a security risk where a malicious FTP Server may cause wget
to write to files outside of the intended directories through a specially crafted .LISTING file.wget
will recurse into to depth. In order to prevent one from accidentally downloading very large websites when using recursion this is limited to a depth of 5 by default, i.e., it will traverse at most 5 directories deep starting from the provided URL. Set -l 0
or -l inf
for infinite recursion depth.
wget -r -l 0 http:///1.html
Ideally, one would expect this to download just 1.html. but unfortunately this is not the case, because -l 0
is equivalent to -l inf
---that is, infinite recursion. To download a single HTML page (or a handful of them), specify them all on the command line and leave away -r and -l. To download the essential items to view a single HTML page, see page requisites.
--delete-after: This option tells wget
to delete every single file it downloads, after having done so. It is useful for pre-fetching popular pages through a proxy, e.g.:
wget -r -nd --delete-after http://whatever.com/~popular/page/The -r option is to retrieve recursively, and -nd to not create directories.
-k, --convert-links: After the download is complete, convert the links in the document to make them suitable for local viewing. This affects not only the visible hyperlinks, but any part of the document that links to external content, such as embedded images, links to style sheets, hyperlinks to non-HTML content, etc.
Each link will be changed in one of the two ways:
The links to files that have been downloaded by wget
will be changed to refer to the file they point to as a relative link. Example: if the downloaded file /foo/doc.html links to /bar/img.gif, also downloaded, then the link in doc.html will be modified to point to ../bar/img.gif. This kind of transformation works reliably for arbitrary combinations of directories.
The links to files that have not been downloaded by wget
will be changed to include host name and absolute path of the location they point to. Example: if the downloaded file /foo/doc.html links to /bar/img.gif (or to ../bar/img.gif), then the link in doc.html will be modified to point to http://hostname/bar/img.gif. Because of this, local browsing works reliably: if a linked file was downloaded, the link will refer to its local name; if it was not downloaded, the link will refer to its full Internet address rather than presenting a broken link. The fact that the former links are converted to relative links ensures that you can move the downloaded hierarchy to another directory.
Note that only at the end of the download can wget
know which links have been downloaded. Because of that, the work done by -k will be performed at the end of all the downloads.
--convert-file-only: This option converts only the filename part of the URLs, leaving the rest of the URLs untouched. This filename part is sometimes referred to as the "basename", although we avoid that term here in order not to cause confusion.
It works particularly well in conjunction with --adjust-extension, although this coupling is not enforced. It proves useful to populate Internet caches with files downloaded from different hosts.
Example: if some link points to //foo.com/bar.cgi?xyz with --adjust-extension asserted and its local destination is intended to be ./foo.com/bar.cgi?xyz.css, then the link would be converted to //foo.com/bar.cgi?xyz.css. Note that only the filename part has been modified. The rest of the URL has been left untouched, including the net path ("//") which would otherwise be processed by wget
and converted to the effective scheme (ie. "http://").
-K, --backup-converted: When converting a file, back up the original version with a .orig suffix. Affects the behavior of -N.
-m, --mirror: Turn on options suitable for mirroring. This option turns on recursion and time-stamping, sets infinite recursion depth and keeps FTP directory listings. It is currently equivalent to -r -N -l inf
--no-remove-listing.
-p, --page-requisites: This option causes wget
to download all the files that are necessary to properly display a given HTML page. This includes such things as inlined images, sounds, and referenced stylesheets.
wget
interpreted comments strictly, which resulted in missing links in many web pages that displayed fine in browsers, but had the misfortune of containing non-compliant comments. Beginning with version 1.9, wget
has joined the ranks of clients that implements "naive" comments, terminating each comment at the first occurrence of -->.wget
will ignore all the FTP links.wget
has an internal table of HTML tag / attribute pairs that it considers when looking for linked documents during a recursive retrieval. If a user wants only a subset of those tags to be considered, however, he or she should be specify such tags in a comma-separated list with this option.wget --ignore-tags=a,area -H -k -K -r http://site/documentHowever, the author of this option came across a page with tags like "" and came to the realization that specifying tags to ignore was not enough. One can’t just tell
wget
to ignore "", because then stylesheets will not be downloaded. Now the best bet for downloading a single page and its requisites is the dedicated --page-requisites option.-A *.txt
will match file1.txt, but also file2.TXT, file3.TxT, and so on.wget -r --ftp-user=username --ftp-password=password ftp://providers-server/directory-or-file-you-want-to-download/