wget Command: Options, Save Locations with -O, -P, and Resuming with -c

Test environmentRHEL familyAlmaLinux 9.8root account
Network commandswgetLocation/usr/bin/wget

The wget command downloads files at HTTP, HTTPS and FTP addresses from the Linux terminal. On an AlmaLinux 9 server, a download of an Apache Tomcat archive was stopped at 21% and run again with the -c option, which skipped the part already received and resumed only the remaining 9.8M, and the downloaded file matched the official SHA-512 checksum.

The save paths in the output below are example values. Files were downloaded only from the example domain example.com, the official Apache and GNU distribution servers (ftp.gnu.org) and the kernel.org home page, and lines containing cache server names were removed from the response headers.

1️⃣ Basic wget command usage and reading the output

The basic form of the command is wget, options and address, in that order. Given only an address and no options, wget saves the file in the current folder under the file name at the end of the address, and if the address ends with a slash, it uses the name index.html.

cd /root/work
wget https://example.com/
--2026-10-29 01:07:46--  https://example.com/
Resolving example.com (example.com)... 2606:4700:10::ac42:93f3, 2606:4700:10::6814:179a, 172.66.147.243, ...
Connecting to example.com (example.com)|2606:4700:10::ac42:93f3|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: 'index.html'

index.html              [ <=>                ]     577  --.-KB/s    in 0s

2026-10-29 01:07:46 (19.1 MB/s) - 'index.html' saved [577]

The output appears in this order: name lookup, connection, response, size, save location, progress bar and result. If the response line is 200 OK, the server is sending the file; the Length line shows the file size and type, and the last saved line shows the number of bytes saved. If an IPv6 address comes first on the Resolving line, wget connects over IPv6 first.

When a download finishes, wget leaves its result as an exit code. If messages are turned off with -q and only the exit code is printed, a success gives 0.

wget -q -O /root/work/dl/example.html https://example.com/
echo $?
0

Requesting an address that does not exist gives an [ERROR 404: Not Found.] line after the 404 response, and the exit code is 8.

wget -O /root/work/dl/nosuch.html https://example.com/nosuch.html
--2026-10-29 01:05:03--  https://example.com/nosuch.html
Resolving example.com (example.com)... 2606:4700:10::ac42:93f3, 2606:4700:10::6814:179a, 172.66.147.243, ...
Connecting to example.com (example.com)|2606:4700:10::ac42:93f3|:443... connected.
HTTP request sent, awaiting response... 404 Not Found
2026-10-29 01:05:03 ERROR 404: Not Found.
echo $?
8

In scripts, this code is used to check whether a download succeeded. There are nine codes, and 0, 4 and 8 came up in this post.

Exit codeMeaning (according to the manual)When it came up in this post
0No problemsSuccessful download with -q, existing address checked with --spider
1Generic error—
2Options could not be parsed—
3File read or write error—
4Network error-T 3 -t 2 against 192.0.2.1, which does not respond
5SSL certificate verification failed—
6Username and password authentication failed—
7Protocol error—
8The server sent an error response (404, etc.)404 for an address that does not exist, broken link from --spider

2️⃣ Save locations with wget -O, -P and the -o log file

If files are saved in the current folder, as the default behavior does, it is hard to know where a file will end up when wget runs from a script or cron. So the save location is written out directly: the folder with -P, or the file path with -O.

wget -P /root/work/dl/ https://example.com/
--2026-10-29 01:19:31--  https://example.com/
Resolving example.com (example.com)... 2606:4700:10::6814:179a, 2606:4700:10::ac42:93f3, 172.66.147.243, ...
Connecting to example.com (example.com)|2606:4700:10::6814:179a|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: '/root/work/dl/index.html'

index.html              [ <=>                ]     577  --.-KB/s    in 0s

2026-10-29 01:19:31 (18.7 MB/s) - '/root/work/dl/index.html' saved [577]

-P sets only the folder and takes the file name from the address. Running the same command once more leaves the existing index.html as it is and saves a new file with .1 added to the end of its name.

wget -P /root/work/dl/ https://example.com/
--2026-10-29 01:19:31--  https://example.com/
Resolving example.com (example.com)... 2606:4700:10::ac42:93f3, 2606:4700:10::6814:179a, 104.20.23.154, ...
Connecting to example.com (example.com)|2606:4700:10::ac42:93f3|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: '/root/work/dl/index.html.1'

index.html.1            [ <=>                ]     577  --.-KB/s    in 0s

2026-10-29 01:19:32 (23.2 MB/s) - '/root/work/dl/index.html.1' saved [577]
wget -O /root/work/dl/example.html https://example.com/
--2026-10-29 01:04:06--  https://example.com/
Resolving example.com (example.com)... 2606:4700:10::ac42:93f3, 2606:4700:10::6814:179a, 172.66.147.243, ...
Connecting to example.com (example.com)|2606:4700:10::ac42:93f3|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: '/root/work/dl/example.html'

/root/work/dl/examp     [ <=>                ]     577  --.-KB/s    in 0s

2026-10-29 01:04:07 (13.9 MB/s) - '/root/work/dl/example.html' saved [577]

-O saves to the path written, regardless of the address, and if the same file exists, that file is overwritten. The save path appears truncated at the very start of the progress bar line.

Giving a hyphen after -O sends the content to standard output instead of a file, so it can be piped to another command. -q is added as well so that messages do not mix in.

wget -q -O - https://example.com/ | head -n 4
<!doctype html><html lang=en><head><meta charset=utf-8><link rel=icon href=data:,><meta name=viewport content="width=device-width,initial-scale=1"><title>Example Domain</title><style>html{color-scheme:light dark;background:light-dark(#eee,#222)}body{font:16px/1.6 system-ui,sans-serif;max-width:26em;margin:auto;padding:25vh 2em 2em;text-align:center}</style></head><body><p>This domain is for use in documentation examples without needing permission. This is not a service; avoid relying on it for testing and monitoring purposes.</p><script src=/s.js></script></body></html>

The HTML of example.com is a single line, so head also prints only one line.

Uppercase -O and lowercase -o have similar names but do different jobs. Lowercase -o sets the log file that messages are written to. So nothing appears on the screen, and the lines from connection through saving remain in the log file.

wget -o /root/work/log/wget.log -P /root/work/dl/ https://example.com/
echo $?
0
cat /root/work/log/wget.log
--2026-10-29 01:08:11--  https://example.com/
Resolving example.com (example.com)... 2606:4700:10::6814:179a, 2606:4700:10::ac42:93f3, 104.20.23.154, ...
Connecting to example.com (example.com)|2606:4700:10::6814:179a|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: '/root/work/dl/index.html'

     0K                                                        25.6M=0s

2026-10-29 01:08:11 (25.6 MB/s) - '/root/work/dl/index.html' saved [577]

The log file gets dot progress lines starting with 0K instead of the progress bar. The diagram below lets you compare, with buttons, where each of the four options sends the content and the messages.

💾 Where wget save options send the output
Explainer diagram
💾 Save option
# wget -P /root/work/dl/ https://example.com/wget -O /root/work/dl/example.html https://example.com/wget -q -O - https://example.com/wget -o /root/work/log/wget.log -P /root/work/dl/ https://example.com/
🌐 Address
🔗https://example.com/File to download
➜
⬇️ wget
📦ContentsDownloaded file bytes
💬MessagesConnection, progress bar, result lines
➜
📂 Destination
📦 Contents/root/work/dl/index.html/root/work/dl/example.htmlScreen (standard output)/root/work/dl/index.html
💬 MessagesScreenScreenTurned off with -q/root/work/log/wget.log
-P sets only the folder. The file name is taken from the end of the address, so the file is saved as index.html, and if the same name exists, .1 is added to the end.
-O sets the whole file path. Regardless of the address, the file is saved as example.html, and an existing file is overwritten.
Giving a hyphen after -O sends the content to the screen instead of a file. This is used to pipe it to another command. -q is added as well so that messages do not mix in.
Lowercase -o changes where messages go. The file is still saved in the -P folder, and the connection and progress lines that appeared on the screen go to the log file.

3️⃣ Resuming downloads with wget -c, rate limits and retries

Even with a save location set, large files can be cut off in the middle of a download. A Tomcat 9.0.123 archive was being downloaded with --limit-rate=1m, limited to 1MB per second, and was stopped at 21% with Ctrl+C.

wget --limit-rate=1m -P /root/work/ https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.123/bin/apache-tomcat-9.0.123.tar.gz
--2026-10-29 01:07:47--  https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.123/bin/apache-tomcat-9.0.123.tar.gz
Resolving dlcdn.apache.org (dlcdn.apache.org)... 2a04:4e42::644, 151.101.2.132
Connecting to dlcdn.apache.org (dlcdn.apache.org)|2a04:4e42::644|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 13233352 (13M) [application/x-gzip]
Saving to: '/root/work/apache-tomcat-9.0.123.tar.gz'

che-tomcat-9.0.123.  21%[===>                ]   2.65M  1024KB/s
^C
ls -l /root/work/
total 2928
-rw-r--r-- 1 root root 2997039 Oct 29 01:07 apache-tomcat-9.0.123.tar.gz

The interrupted file remains at 2,997,039 bytes. Running the same command again with -c added requests the data that follows this size. Downloading the same address again without -c does not resume; it downloads a new file, with .1 added after the name, from the beginning.

wget -c -P /root/work/ https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.123/bin/apache-tomcat-9.0.123.tar.gz
--2026-10-29 01:07:50--  https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.123/bin/apache-tomcat-9.0.123.tar.gz
Resolving dlcdn.apache.org (dlcdn.apache.org)... 2a04:4e42::644, 151.101.2.132
Connecting to dlcdn.apache.org (dlcdn.apache.org)|2a04:4e42::644|:443... connected.
HTTP request sent, awaiting response... 206 Partial Content
Length: 13233352 (13M), 10236313 (9.8M) remaining [application/x-gzip]
Saving to: '/root/work/apache-tomcat-9.0.123.tar.gz'

apache-tomcat-9.0.1 100%[++++===============>]  12.62M  --.-KB/s    in 0.04s

2026-10-29 01:07:50 (262 MB/s) - '/root/work/apache-tomcat-9.0.123.tar.gz' saved [13233352/13233352]

The response changes to [206 Partial Content], and the Length line shows the remaining 9.8M out of the total 13M. The + signs inside the bar are the part already received. According to the manual, -c works only on HTTP servers that accept Range requests and on FTP servers.

ls -l /root/work/
total 15168
-rw-r--r-- 1 root root 13233352 Oct  6 19:11 apache-tomcat-9.0.123.tar.gz

The time on the fully downloaded file is Oct 6 19:11. wget applies the Last-Modified time sent by the server to the downloaded file as is.

Whether the resumed file matched the original was checked with the .sha512 file that Apache distributes alongside it.

wget -q -P /root/work/ https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.123/bin/apache-tomcat-9.0.123.tar.gz.sha512
cd /root/work
sha512sum -c apache-tomcat-9.0.123.tar.gz.sha512
apache-tomcat-9.0.123.tar.gz: OK

When [OK] appears, the file that was interrupted and resumed is identical, down to the byte, to the official distribution file.

-N downloads only when the server file is newer than the local file. Requesting the same .sha512 again with -N gave a [304 Not Modified] response, and the download was skipped.

wget -N -P /root/work/ https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.123/bin/apache-tomcat-9.0.123.tar.gz.sha512
--2026-10-29 01:05:14--  https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.123/bin/apache-tomcat-9.0.123.tar.gz.sha512
Resolving dlcdn.apache.org (dlcdn.apache.org)... 2a04:4e42::644, 151.101.2.132
Connecting to dlcdn.apache.org (dlcdn.apache.org)|2a04:4e42::644|:443... connected.
HTTP request sent, awaiting response... 304 Not Modified
File '/root/work/apache-tomcat-9.0.123.tar.gz.sha512' not modified on server. Omitting download.

For servers that do not respond, -T sets the seconds to wait and -t sets the number of tries. The defaults are a 900-second read timeout and 20 tries, so leaving them as they are can keep wget stuck for a long time. When -T 3 -t 2 was given to 192.0.2.1, an address reserved for documentation examples, there was no response, so wget tried twice and then ended with exit code 4.

wget -T 3 -t 2 -O /root/work/dl/t.html http://192.0.2.1/
--2026-10-29 01:05:25--  http://192.0.2.1/
Connecting to 192.0.2.1:80... failed: Connection timed out.
Retrying.

--2026-10-29 01:05:29--  (try: 2)  http://192.0.2.1/
Connecting to 192.0.2.1:80... failed: Connection timed out.
Giving up.
echo $?
4

Even when a download with -O fails with a 404 or a timeout, an empty file is left at that path. After the two failures above, the two files checked with ls were both 0 bytes.

ls -l /root/work/dl/nosuch.html /root/work/dl/t.html
-rw-r--r-- 1 root root 0 Oct 29 01:05 /root/work/dl/nosuch.html
-rw-r--r-- 1 root root 0 Oct 29 01:05 /root/work/dl/t.html

Requesting the same 404 with -P does not create a file.

wget -q -P /root/work/dl/ https://example.com/nosuch2.html
echo $?
8
ls -l /root/work/dl/nosuch2.html
ls: cannot access '/root/work/dl/nosuch2.html': No such file or directory

Checking with ls shows [No such file or directory], meaning nosuch2.html does not exist. Because -O leaves an empty file even on failure, a script that uses -O checks that the exit code is 0 before reading that file.

4️⃣ wget options, multiple files with -i and background downloads with -b

When there are several files to download, a file listing the addresses, one per line, is passed with -i. Adding -nv prints only one result line per file.

cat /root/work/urls.txt
https://example.com/
https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.123/bin/apache-tomcat-9.0.123.tar.gz.sha512
wget -nv -i /root/work/urls.txt -P /root/work/list/
2026-10-29 01:05:14 URL:https://example.com/ [577] -> "/root/work/list/index.html" [1]
2026-10-29 01:05:14 URL:https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.123/bin/apache-tomcat-9.0.123.tar.gz.sha512 [158/158] -> "/root/work/list/apache-tomcat-9.0.123.tar.gz.sha512" [1]
FINISHED --2026-10-29 01:05:14--
Total wall clock time: 0.3s
Downloaded: 2 files, 735 in 0s (14.7 MB/s)

The last three lines are the overall summary for -i, showing the number of files downloaded and their total size.

Long downloads are run in the background with -b. According to the manual, giving only -b without -o creates a wget-log file in the current folder, so the log path was written as well.

wget -b -o /root/work/log/bg.log -P /root/work/bg/ https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.123/bin/apache-tomcat-9.0.123.tar.gz
Continuing in background, pid 3623651.
tail -n 4 /root/work/log/bg.log
 12900K .......... .......... ...                             100%  423M=0.07s

2026-10-29 01:05:22 (183 MB/s) - '/root/work/bg/apache-tomcat-9.0.123.tar.gz' saved [13233352/13233352]

The shell prompt comes back right away, and the download continues as a background process. When it finishes, [saved] is left on the last line of the log.

The options are gathered in the two tabs below.

OptionCopyDescription
-O, --output-documentFILESets the file path to save to
-P, --directory-prefixPREFIXSets only the folder to save to
-q, --quietTurns off messages
-o, --output-fileLOGFILESends messages to a log file
-c, --continueResumes downloading an interrupted file
-N, --timestampingDownloads only when newer
-nc, --no-clobberDoes not download if the file was already downloaded
-T, --timeoutSECONDSSets the seconds to wait
-t, --triesNUMBERSets the number of tries
-i, --input-fileFILEMultiple addresses at once
-nv, --no-verbosePrints only one result line per file
-b, --backgroundDownloads in the background
--spiderChecks only the address without downloading
-S, --server-responseShows response headers
-r, --recursiveFollows links to download
-l, --levelDEPTHSets how deep to follow links
--limit-rateAMOUNTRate limit
OptionCopyDescription
--userUSERUsername for FTP and HTTP downloads
--passwordPASSWORDPassword for FTP and HTTP downloads
--ask-passwordPrompts for the password on each connection (cannot be used with --password)
--ftp-userUSERUsername for the FTP server
--ftp-passwordPASSWORDPassword for the FTP server
-U, --user-agentAGENTIdentifies itself to the HTTP server as AGENT
--headerHEADER-LINESends one extra header line with each HTTP request
--no-check-certificateDoes not check the server certificate against the certificate authorities
-4, --inet4-onlyConnects over IPv4 addresses only
-w, --waitSECONDSSeconds to wait between downloads
-m, --mirrorTurns on options suited to mirroring (recursive, timestamp comparison, unlimited depth)
-np, --no-parentDoes not ascend to the parent folder when downloading recursively
-nd, --no-directoriesDoes not create a folder structure when downloading recursively
-k, --convert-linksConverts links in documents after downloading so they can be viewed locally
-A, --acceptACCLISTList of file name endings or patterns to download (comma-separated)

To check only whether an address is alive before downloading, use --spider. It does not save the file and checks only the response code.

wget --spider https://example.com/
Spider mode enabled. Check if remote file exists.
--2026-10-29 01:05:03--  https://example.com/
Resolving example.com (example.com)... 2606:4700:10::6814:179a, 2606:4700:10::ac42:93f3, 104.20.23.154, ...
Connecting to example.com (example.com)|2606:4700:10::6814:179a|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Remote file exists and could contain further links,
but recursion is disabled -- not retrieving.
echo $?
0
wget --spider https://example.com/nosuch.html
Spider mode enabled. Check if remote file exists.
--2026-10-29 01:05:04--  https://example.com/nosuch.html
Resolving example.com (example.com)... 2606:4700:10::ac42:93f3, 2606:4700:10::6814:179a, 172.66.147.243, ...
Connecting to example.com (example.com)|2606:4700:10::ac42:93f3|:443... connected.
HTTP request sent, awaiting response... 404 Not Found
Remote file does not exist -- broken link!!!
echo $?
8

An existing address ends with exit code 0, and an address that does not exist ends with 8 along with the [broken link] message. Scripts that check links use this code as is.

Adding -S also shows the response headers sent by the server.

wget -S --spider https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.123/bin/apache-tomcat-9.0.123.tar.gz
Spider mode enabled. Check if remote file exists.
--2026-10-29 01:03:54--  https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.123/bin/apache-tomcat-9.0.123.tar.gz
Resolving dlcdn.apache.org (dlcdn.apache.org)... 2a04:4e42::644, 151.101.2.132
Connecting to dlcdn.apache.org (dlcdn.apache.org)|2a04:4e42::644|:443... connected.
HTTP request sent, awaiting response...
  HTTP/1.1 200 OK
  Connection: keep-alive
  Content-Length: 13233352
  Server: Apache
  Last-Modified: Tue, 06 Oct 2026 19:11:51 GMT
  ETag: "c9ecc8-65d30c56390be"
  Access-Control-Allow-Origin: *
  Content-Type: application/x-gzip
  Via: 1.1 varnish, 1.1 varnish
  Accept-Ranges: bytes
  Age: 2047
  Date: Thu, 29 Oct 2026 01:03:54 GMT
  X-Cache: HIT, HIT
  X-Cache-Hits: 400, 0
Length: 13233352 (13M) [application/x-gzip]
Remote file exists.

Content-Length is the file size, and Last-Modified is the time that -N compares with the local file. [Accept-Ranges: bytes] means this server accepts the resume requests from -c.

-r, which follows links to download multiple files, sets its depth with -l. When -l 1 was given to example.com, wget downloaded the page, checked robots.txt and went on to the s.js that the page loads, downloading two files in all.

wget -r -l 1 -P /root/work/mirror/ https://example.com/
--2026-10-29 01:05:38--  https://example.com/
Resolving example.com (example.com)... 2606:4700:10::ac42:93f3, 2606:4700:10::6814:179a, 172.66.147.243, ...
Connecting to example.com (example.com)|2606:4700:10::ac42:93f3|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: '/root/work/mirror/example.com/index.html'

     0K                                                        28.7M=0s

2026-10-29 01:05:38 (28.7 MB/s) - '/root/work/mirror/example.com/index.html' saved [577]

Loading robots.txt; please ignore errors.
--2026-10-29 01:05:38--  https://example.com/robots.txt
Reusing existing connection to [example.com]:443.
HTTP request sent, awaiting response... 404 Not Found
2026-10-29 01:05:38 ERROR 404: Not Found.

--2026-10-29 01:05:38--  https://example.com/s.js
Reusing existing connection to [example.com]:443.
HTTP request sent, awaiting response... 200 OK
Length: 1963 (1.9K) [text/javascript]
Saving to: '/root/work/mirror/example.com/s.js'

     0K .                                                     100% 17.6M=0s

2026-10-29 01:05:38 (17.6 MB/s) - '/root/work/mirror/example.com/s.js' saved [1963/1963]

FINISHED --2026-10-29 01:05:38--
Total wall clock time: 0.2s
Downloaded: 2 files, 2.5K in 0s (19.3 MB/s)
find /root/work/mirror -type f
/root/work/mirror/example.com/index.html
/root/work/mirror/example.com/s.js

A folder named after the domain is created under the -P folder, and the files are saved inside it following the site's paths.

🔲 wget command simulator

In the simulator below, wget can be typed directly with the -O, -P, -o, -c, -N, -i and --spider options. The addresses that can be downloaded and the output are the same example values as in the text, and the flow can be followed all the way to resuming the Tomcat file cut off at 21% with -c and then checking it with sha512sum.

wget command simulatorwget · root Account
[root@server work]#
Use the ↑↓ keys to recall commands you typed earlier.

6️⃣ Practical wget command examples

  • ↪️ Extracting a downloaded tar.gz right away and skipping files already downloaded, common beginner mistakes

🔲 Extracting a downloaded tar.gz right away and skipping files already downloaded

To extract an installation file right after downloading it, the archive is passed to tar instead of being saved. When hello-2.12.1.tar.gz was downloaded with wget -qO- and passed to tar -xzf -, it ended with exit code 0, and the hello-2.12.1 folder was extracted into the src folder.

mkdir src
wget -qO- https://ftp.gnu.org/gnu/hello/hello-2.12.1.tar.gz | tar -xzf - -C src; echo $?
0
ls src; ls src/hello-2.12.1 | head -5
hello-2.12.1
ABOUT-NLS
AUTHORS
COPYING
ChangeLog
ChangeLog.O

When the same command is repeated, as with cron, -nc is added. -nc does not download a file that has already been downloaded. When it was run twice, the second run showed the [already there; not retrieving.] line, and the dl folder still held just one file.

wget -q -nc -P dl https://ftp.gnu.org/gnu/hello/hello-2.12.1.tar.gz.sig; echo $?
0
wget -nc -P dl https://ftp.gnu.org/gnu/hello/hello-2.12.1.tar.gz.sig; echo $?
File 'dl/hello-2.12.1.tar.gz.sig' already there; not retrieving.

0
ls dl
hello-2.12.1.tar.gz.sig

🔲 Common Beginner Mistakes

Addresses containing a question mark and the & sign are wrapped in quotes. If [?C=M&O=D] is added without quotes, the shell reads the & sign as running in the background, and only ?C=M is passed to wget. [C=M&O=D] is a value that sorts by modification time, newest first, so the listing downloaded without quotes started with the old hello-1.3, while the listing downloaded with quotes started with the newest hello-2.12.3.

wget -q -O list.html https://ftp.gnu.org/gnu/hello/?C=M&O=D
grep -o "hello-[0-9.]*tar.gz\"" list.html | head -3
hello-1.3.tar.gz"
hello-2.1.1.tar.gz"
hello-2.1.0.tar.gz"
wget -q -O list.html "https://ftp.gnu.org/gnu/hello/?C=M&O=D"
grep -o "hello-[0-9.]*tar.gz\"" list.html | head -3
hello-2.12.3.tar.gz"
hello-2.12.2.tar.gz"
hello-2.12.1.tar.gz"

When -O and -P are given together, the path written with -O is used as is. When it was run with -P dl added, hello.sig was saved in the current folder instead of the dl folder.

wget -q -P dl -O hello.sig https://ftp.gnu.org/gnu/hello/hello-2.12.1.tar.gz.sig; echo $?; ls hello.sig dl
0
hello.sig

dl:
hello-2.12.1.tar.gz.sig
hello.html
kernel.html

🔲 How to read wget results

When an address redirects to another address, the response line appears twice. When http://kernel.org/ was downloaded and only the response lines were picked out, the first response was [301 Moved Permanently], and the Location line showed the new address https://kernel.org/ along with [following]. The second request showed [200 OK] and the Length line.

wget -O dl/kernel.html http://kernel.org/ 2>&1 | grep -E "HTTP request|Location|Length"
HTTP request sent, awaiting response... 301 Moved Permanently
Location: https://kernel.org/ [following]
HTTP request sent, awaiting response... 200 OK
Length: 20436 (20K) [text/html]

So even if the first response is 301, the download has not failed; the last response line and the Length line are the result for the file actually downloaded.

The -O, -P and -c options can be tried by typing them directly in the wget command simulator.

🔢 FAQ & Recommended Content

Both commands fetch the content of an address, but according to the official documentation, wget saves what it downloads to a file by default and can follow links with -r to download multiple files. Unless told otherwise, curl sends what it receives to standard output. In wget, the same behavior is achieved with -O -.

On AlmaLinux 9, the wget package from the appstream repository is installed with [dnf install wget]. The source of the wget 1.21 package on the test server was also appstream. On the Debian family, [apt install wget] installs the package of the same name.

According to the official documentation, the account is passed with --user and --password, and --ftp-user and --ftp-password are used to set it for FTP only. The manual states that a password written on the command line is visible to anyone through the ps command. So the password is either entered at run time with --ask-password or kept in a .netrc file whose permissions are restricted so that other accounts cannot read it.

ℹ️ Affiliate Disclosure
This site's content contains affiliate links. When a visitor buys a product or service through one of them, the site receives a commission from the seller. The amount the buyer pays(it goes down during event discounts ↓)does not go up. Posted prices, discounts, and stock reflect the time of writing and may differ, so confirm with the seller before buying. Products are chosen and reviewed by our own standards, and commissions do not affect the order or content of reviews.

Leave a Reply

Your email address will not be published. Required fields are marked *

Prove your humanity: 9   +   10   =