The non-interactive network downloader
|
-O file
--output-document=file
The documents will not be written to the appropriate files, but all will be concatenated together and
written to file. If - is used as file, documents will be printed to standard output, disabling link
conversion. (Use ./- to print to a file literally named -.)
Use of -O is not intended to mean simply "use the name file instead of the one in the URL;" rather,
it is analogous to shell redirection: wget -O file http://foo is 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; -k can be used only when the output is a regular file.
|
wget [option]... [URL]...
|
Pipelines
A pipeline is a sequence of one or more commands separated by one of the control operators | or |&. The
format for a pipeline is:
[time [-p]] [ ! ] command [ [|⎪|&] command2 ... ]
The standard output of command is connected via a pipe to the standard input of command2. This
connection is performed before any redirections specified by the command (see REDIRECTION below). If |&
is used, the standard error of command is connected to command2's standard input through the pipe; it is
shorthand for 2>&1 |. This implicit redirection of the standard error is performed after any
redirections specified by the command.
The return status of a pipeline is the exit status of the last command, unless the pipefail option is
enabled. If pipefail is enabled, the pipeline's return status is the value of the last (rightmost)
command to exit with a non-zero status, or zero if all commands exit successfully. If the reserved word
! precedes a pipeline, the exit status of that pipeline is the logical negation of the exit status as
described above. The shell waits for all commands in the pipeline to terminate before returning a value.
If the time reserved word precedes a pipeline, the elapsed as well as user and system time consumed by
its execution are reported when the pipeline terminates. The -p option changes the output format to that
specified by POSIX. When the shell is in posix mode, it does not recognize time as a reserved word if
the next token begins with a `-'. The TIMEFORMAT variable may be set to a format string that specifies
how the timing information should be displayed; see the description of TIMEFORMAT under Shell Variables
below.
When the shell is in posix mode, time may be followed by a newline. In this case, the shell displays the
total user and system time consumed by the shell and its children. The TIMEFORMAT variable may be used
to specify the format of the time information.
Each command in a pipeline is executed as a separate process (i.e., in a subshell).
|
compress or expand files
|
-B URL
--base=URL
Resolves relative links using URL as the point of reference, when reading links from an HTML file
specified via the -i/--input-file option (together with --force-html, or when the input file was
fetched remotely from a server describing it as HTML). This is equivalent to the presence of a "BASE"
tag in the HTML input file, with URL as the value for the "href" attribute.
For instance, if you specify http://foo/bar/a.html for URL, and Wget reads ../baz/b.html from the
input file, it would be resolved to http://foo/baz/b.html.
|
-i file
--input-file=file
Read URLs from a local or external file. If - is specified as file, URLs are read from the standard
input. (Use ./- to read from a file literally named -.)
If this function is used, no URLs need be present on the command line. If there are URLs both on the
command line and in an input file, those on the command lines will be the first ones to be retrieved.
If --force-html is not specified, then file should consist of a series of URLs, one per line.
However, if you specify --force-html, the document will be regarded as html. In that case you may
have problems with relative links, which you can solve either by adding "<base href="url">" to the
documents or by specifying --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.
|
-F
--force-html
When input is read from a file, force it to be treated as an HTML file. This enables you to retrieve
relative links from existing HTML files on your local disk, by adding "<base href="url">" to HTML, or
using the --base command-line option.
|
-c
--continue
Continue getting a partially-downloaded file. This is useful when you want to finish up a download
started by a previous instance of Wget, or by another program. For instance:
|
-T seconds
--timeout=seconds
Set the network timeout to seconds seconds. This is equivalent to specifying --dns-timeout,
--connect-timeout, and --read-timeout, all at the same time.
When interacting with the network, 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.
All timeout-related options accept decimal values, as well as subsecond values. For example, 0.1
seconds is a legal (though unwise) choice of timeout. Subsecond timeouts are useful for checking
server response times or for testing network latency.
|
-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.
|
Recursive Retrieval Options
-r
--recursive
Turn on recursive retrieving. The default maximum depth is 5.
|
-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.
Ordinarily, when downloading a single HTML page, any requisite documents that may be needed to
display it properly are not downloaded. Using -r together with -l can help, but since Wget does not
ordinarily distinguish between external and inlined documents, one is generally left with "leaf
documents" that are missing their requisites.
For instance, say document 1.html contains an "<IMG>" tag referencing 1.gif and an "<A>" tag pointing
to external document 2.html. Say that 2.html is similar but that its image is 2.gif and it links to
3.html. Say this continues up to some arbitrarily high number.
If one executes the command:
wget -r -l 2 http://<site>/1.html
then 1.html, 1.gif, 2.html, 2.gif, and 3.html will be downloaded. As you can see, 3.html is without
its requisite 3.gif because Wget is simply counting the number of hops (up to 2) away from 1.html in
order to determine where to stop the recursion. However, with this command:
wget -r -l 2 -p http://<site>/1.html
all the above files and 3.html's requisite 3.gif will be downloaded. Similarly,
wget -r -l 1 -p http://<site>/1.html
will cause 1.html, 1.gif, 2.html, and 2.gif to be downloaded. One might think that:
wget -r -l 0 -p http://<site>/1.html
would download just 1.html and 1.gif, 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, all specified on the command-line or in a -i URL input file) and its (or their) requisites,
simply leave off -r and -l:
wget -p http://<site>/1.html
Note that Wget will behave as if -r had been specified, but only that single page and its requisites
will be downloaded. Links from that page to external documents will not be followed. Actually, to
download a single page and all its requisites (even if they exist on separate websites), and make
sure the lot displays properly locally, this author likes to use a few options in addition to -p:
wget -E -H -k -K -p http://<site>/<document>
To finish off this topic, it's worth knowing that Wget's idea of an external document link is any URL
specified in an "<A>" tag, an "<AREA>" tag, or a "<LINK>" tag other than "<LINK REL="stylesheet">".
|