How to Download Files from the Command Line in Linux Using Wget

Downloading files on a server without a browser can get messy when you need to resume a broken ISO download, limit transfer speeds, or download multiple URLs. Here’s how to handle it all with Wget, from basic downloads to retries, mirroring, and secure authentication.

If you manage Linux servers, you regularly download files from the terminal, including release tarballs, ISO images, installation scripts, and backups stored on remote machines.

A simple download is usually enough, but sooner or later, a 3 GB ISO stops at 80% over a slow connection, or a download consumes bandwidth needed by production traffic. That’s when you need more control than simply restarting the download and hoping for the best.

GNU Wget is a free, non-interactive command-line downloader that supports HTTP, HTTPS, FTP, and FTPS. It can resume interrupted downloads, retry network failures, limit bandwidth usage, run in the background, read URLs from a file, and mirror entire websites for offline use. Because it doesn’t require interactive input, it works well in scripts, cron jobs, and SSH sessions.

The current stable release is Wget 1.25.0, released in November 2024, and most distributions ship a 1.2x version. However, one change matters if you’re using a recent Fedora release: the wget command may no longer refer to GNU Wget 1.x. Let’s look at what changed first.

Wget vs Wget2: Which One Your Distribution Ships

Before running the examples, check which version of Wget your distribution provides, because some options behave differently between the two versions.

Wget2 is the successor to GNU Wget, rewritten from scratch with support for HTTP/2 and parallel downloads. Starting with Fedora 40, the wget2-wget package replaces the traditional wget package, so running wget on Fedora launches Wget2.

According to the Fedora change proposal, Wget2 is largely a drop-in replacement, but it does not support FTP or WARC (Web ARChive) downloads.

Ubuntu, Debian, Rocky Linux, AlmaLinux, and RHEL generally provide classic GNU Wget 1.x through their wget packages, though the exact version depends on the distribution release.

Both versions use the same basic syntax:

wget [options] [URL]

To identify the version installed on your system, run:

wget --version | head -1

Output:

GNU Wget 1.25.0 built on linux-gnu.

If the output identifies GNU Wget2 instead, you’re using Wget2, and the FTP example later in this guide won’t work. The remaining examples are intended to work with both versions unless a specific difference is noted.

Install Wget on Linux

Most Linux server images include Wget, but minimal container and cloud images may not. If running wget --version returns a “command not found” error, install it using your distribution’s package manager.

On Ubuntu, Debian, and Linux Mint, refresh the package index before installing Wget:

sudo apt update
sudo apt install -y wget

On Rocky Linux, AlmaLinux, and RHEL, install Wget using DNF:

sudo dnf install -y wget

On Fedora 40 and later, the same command installs the wget2-wget package, which provides the wget command through Wget2:

sudo dnf install -y wget

On Arch Linux, install Wget from the official repositories using Pacman:

sudo pacman -S wget

On openSUSE, use Zypper:

sudo zypper install wget

With Wget installed, let’s start with a basic download and build up to more advanced options.

1. Download a Single File with Wget

The simplest way to use Wget is to pass it a URL. It downloads the file into your current directory, using the filename specified by the URL. We’ll use the GNU Wget source tarball as an example throughout the first few sections:

wget https://ftp.gnu.org/gnu/wget/wget-1.25.0.tar.gz

Output:

--2026-10-26 10:15:16--  https://ftp.gnu.org/gnu/wget/wget-1.25.0.tar.gz
Resolving ftp.gnu.org (ftp.gnu.org)... 209.51.188.20, 2001:470:142:3::b
Connecting to ftp.gnu.org (ftp.gnu.org)|209.51.188.20|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 5381232 (5.1M) [application/x-gzip]
Saving to: 'wget-1.25.0.tar.gz'

wget-1.25.0.tar.gz    100%[===================>]   5.13M  3.21MB/s    in 1.6s

2026-10-26 10:15:18 (3.21 MB/s) - 'wget-1.25.0.tar.gz' saved [5381232/5381232]
Note: Verify the file size and transfer details against a real download before publishing this sample output.

The 200 OK response indicates that the server successfully handled the HTTP request. The final saved [x/y] message confirms that Wget saved the expected number of bytes.

If you run the same command again, Wget normally preserves the existing file and saves the new download under a numbered filename, such as wget-1.25.0.tar.gz.1 or .2. This behavior is easy to overlook in scripts that download the same file every night.

2. Save a Download Under a Different Name with -O

Wget’s automatic .1 filename suffix can be inconvenient, especially in scripts. Use the uppercase -O option to specify the output filename. If that file already exists, Wget overwrites it:

wget -O wget-latest.tar.gz https://ftp.gnu.org/gnu/wget/wget-1.25.0.tar.gz

Keep the correct file extension when renaming a download. Saving a .tar.gz archive as wget.zip does not change its format, so unzip will not be able to extract it.

You can also use -O- to send downloaded content to standard output instead of saving it to a file. Combined with -q, which suppresses Wget’s status messages, this lets you inspect a script before running it:

wget -qO- https://get.example.com/install.sh | less

Reviewing an installation script before executing it can help you spot unexpected commands or potentially harmful changes to your server.

3. Download Files into a Specific Directory with -P

Renaming covers single files, but when you download several files into a project or a shared location, it’s simpler to tell wget where to put them. The -P option sets the directory prefix, and wget creates the directory if it doesn’t exist yet:

wget -P ~/downloads/gnu https://ftp.gnu.org/gnu/wget/wget-1.25.0.tar.gz

This keeps your current working directory clean, which matters when you run wget from a script whose working directory you don’t control, such as a cron job.

4. Download Multiple Files at Once with Wget

Wget accepts more than one URL in a single command and downloads them one after another. A common case is grabbing a tarball together with its GPG signature, so you can verify it right after:

wget https://ftp.gnu.org/gnu/wget/wget-1.25.0.tar.gz https://ftp.gnu.org/gnu/wget/wget-1.25.0.tar.gz.sig

Since both files come from the same server, wget reuses the open connection for the second file instead of connecting again, and you will see Reusing existing connection to ftp.gnu.org:443 in the output.

If you need a numbered series of files, you can let the shell generate the URLs with brace expansion. This is a Bash feature rather than a wget option, so the shell expands {1..5} into five separate URLs before wget runs. For example, to download the Linux 6.6.1 to 6.6.5 kernel tarballs:

wget https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-6.6.{1..5}.tar.xz

5. Download a List of URLs from a File with -i

Typing URLs works for two or three files, but for a longer list, or a list another script produces, it’s easier to keep the URLs in a text file and pass it with the -i option. Each URL goes on its own line.

Create the list with nano on Ubuntu and Debian:

nano download-linux.txt

On Rocky Linux, AlmaLinux, and RHEL, minimal installs ship with vi rather than nano, so use vi there:

vi download-linux.txt

Then add the URLs you want to download:

https://releases.ubuntu.com/26.04/ubuntu-26.04.1-live-server-amd64.iso
https://download.rockylinux.org/pub/rocky/10/isos/x86_64/Rocky-10.1-x86_64-dvd1.iso
https://cdimage.debian.org/debian-cd/current/amd64/iso-dvd/debian-13.1.0-amd64-DVD-1.iso
Note: ISO filenames and download paths may change with new releases. Check the official distribution websites for the latest links.

Save the file and exit the editor, then pass it to wget:

wget -i download-linux.txt

Since wget 1.25.0, -i - reads URLs from a pipe continuously until the pipe closes, instead of reading the list only once at startup. This means a script that produces URLs over time can feed wget as it goes.

If this finally explained why your download folder fills up with .1 and .2 copies, share it with someone who’s still deleting duplicate ISOs by hand.

6. Resume an Interrupted Download with -c

Large ISO files are especially prone to interruptions when an SSH session drops or the network connection fails. If you rerun the same Wget command without the appropriate option, Wget typically starts a new download and saves it under a numbered filename, leaving the partial file untouched.

The -c (continue) option tells Wget to resume the existing partial download by requesting the remaining bytes from the server:

wget -c https://releases.ubuntu.com/26.04/ubuntu-26.04.1-live-server-amd64.iso

When the server supports resuming, and the request succeeds, it typically responds with 206 Partial Content rather than 200 OK. The output indicates how much data remains to be downloaded:

HTTP request sent, awaiting response... 206 Partial Content
Length: 3213064192 (3.0G), 2463109120 (2.3G) remaining [application/octet-stream]
Note: The response and file sizes above are illustrative. Actual output depends on the file and the amount already downloaded.

If the server doesn’t support byte-range requests, Wget may need to restart the download. Including -c in commands for large files makes retries more convenient, but always check the output to confirm that the download actually resumed.

7. Retry Failed Downloads with –tries and –waitretry

Resuming a download manually is straightforward when you’re watching the terminal, but automated jobs need to handle temporary failures themselves.

GNU Wget retries failed downloads by default, up to 20 attempts, although some errors are treated as fatal unless you configure additional retry behavior.

To make a download more resilient to temporary network failures and overloaded mirrors, use:

wget -c --tries=10 --waitretry=30 --retry-connrefused --retry-on-http-error=503,429 https://releases.ubuntu.com/26.04/ubuntu-26.04.1-live-server-amd64.iso

Here’s what each option does:

  • -c resumes the existing partial file when a retry is needed, and the server supports it.
  • --tries=10 limits the number of download attempts.
  • --waitretry=30 increases the delay between retries, up to 30 seconds, giving a struggling server time to recover.
  • --retry-connrefused treats connection-refused errors as temporary failures worth retrying.
  • --retry-on-http-error=503,429 retries when the server returns HTTP 503 Service Unavailable or 429 Too Many Requests, provided the installed Wget version supports this option.

Check the installed version’s documentation before using version-specific options, especially on Fedora systems that provide Wget2.

8. Limit Wget Download Speed with –limit-rate

Reliable downloads are useful, but a large transfer running at full speed can consume bandwidth needed by other services. The --limit-rate option caps Wget’s download rate. Use k for kilobytes per second or m for megabytes per second:

wget -c --limit-rate=2m https://releases.ubuntu.com/26.04/ubuntu-26.04.1-live-server-amd64.iso

Wget regulates the transfer rate over time, so the progress indicator may briefly show a higher speed before settling near the configured limit. For more details, see our guide on how to limit file download speed using Wget.

9. Run Wget in the Background with -b and Write a Log with -o

A rate-limited download of a 3 GB ISO can take a long time, and you may not want to keep an SSH session open to monitor it. The -b option starts Wget in the background, returning control of the terminal to you.

By default, Wget writes its output to wget-log in the current directory. Use the lowercase -o option to specify a different log filename:

wget -b -c --limit-rate=2m -o ubuntu-iso.log https://releases.ubuntu.com/26.04/ubuntu-26.04.1-live-server-amd64.iso

Output:

Continuing in background, pid 8999.

Without -o, Wget reports that output will be written to wget-log. Subsequent runs may create numbered log files, such as wget-log.1 and wget-log.2.

To monitor the download, follow the log with tail command:

tail -f ubuntu-iso.log

Example output:

  5600K .......... .......... .......... .......... ..........  0% 2.01M 25m31s
  5650K .......... .......... .......... .......... ..........  0% 1.98M 25m30s
  5700K .......... .......... .......... .......... ..........  0% 2.02M 25m30s

These lines illustrate download progress, transfer speed, and estimated time remaining. Press Ctrl+C to stop following the log; the background download continues running.

Keep in mind that a background Wget process does not survive a server reboot. Combining -b with -c, as shown above, lets you resume an interrupted download by running the command again.

If you’ve ever lost a 3 GB download because your laptop went to sleep, share this with a teammate who still keeps SSH sessions open all night.

10. Check URLs Without Downloading Using –spider

Sometimes you need to check whether a file exists before a deployment script downloads it, or verify that a release URL still works. The --spider option lets Wget check a URL without saving the file locally.

wget –spider https://ftp.gnu.org/gnu/wget/wget-1.25.0.tar.gz

If the requested file does not exist, the output may include a message like this:

HTTP request sent, awaiting response... 404 Not Found
Remote file does not exist -- broken link!!!

The exclamation marks are part of Wget’s own error message. Wget also returns a non-zero exit status when the check fails, allowing you to use it in shell scripts:

wget -q --spider https://ftp.gnu.org/gnu/wget/wget-1.25.0.tar.gz && echo "Release is available"

The message appears only if the URL check succeeds, making this a simple way to verify a download link before proceeding with the next step.

11. Mirror an Entire Website for Offline Use with –mirror

The --spider option checks links without saving files, while mirroring downloads pages and their resources for offline browsing. This is useful for keeping a local copy of internal documentation or archiving a small website before migrating it.

The --mirror option enables recursive downloading and timestamping, allowing Wget to retrieve files at any depth and update files that have changed since the previous run. Combine it with a few additional options to make the downloaded copy easier to browse offline:

wget --mirror --page-requisites --adjust-extension --convert-links --no-parent --wait=1 --random-wait https://docs.tecmint.lan/handbook/

Here’s what each option does:

  • --mirror enables recursive downloading, timestamping, and unlimited recursion depth, along with options to preserve FTP directory listings.
  • --page-requisites downloads resources such as CSS, JavaScript, and images needed to display each page correctly.
  • --adjust-extension adjusts downloaded HTML filenames so pages can be opened locally with the appropriate extension.
  • --convert-links rewrites links in downloaded pages to point to local copies where possible.
  • --no-parent prevents Wget from following links to parent directories above /handbook/.
  • --wait=1 pauses for at least one second between retrievals, while --random-wait varies the delay to reduce the frequency of requests.<

If the site loads resources from a separate domain, such as a CDN, you may need --span-hosts and --domains to include the additional hosts:

wget --mirror --page-requisites --adjust-extension --convert-links --no-parent --span-hosts --domains=docs.tecmint.lan,cdn.tecmint.lan --wait=1 --random-wait https://docs.tecmint.lan/handbook/

Use --restrict-file-names=windows only when you need filenames compatible with Windows, since it changes characters that Windows does not allow in filenames.

Only mirror websites you own or have permission to copy, and respect their robots.txt rules, which Wget follows by default during recursive downloads.

12. Download Password-Protected Files Without Exposing the Password

Internal documentation and private file servers often require authentication. Wget supports HTTP authentication with --user and FTP authentication with --ftp-user. However, passing a password directly with --password=secret can expose it through shell history or process listings.

A safer option for interactive downloads is --ask-password, which prompts you to enter the password:

wget --user=tecmint --ask-password https://files.tecmint.lan/backups/db-2026-10-25.sql.gz

For automated scripts and cron jobs, where interactive prompts aren’t practical, you can store credentials in a `~/.netrc` file that Wget can read automatically.

On Ubuntu and Debian, create the file with Nano:

nano ~/.netrc

On Rocky Linux, AlmaLinux, and RHEL, use Vi if Nano isn’t installed:

vi ~/.netrc

Add the following configuration, replacing the example credentials with your own:

# ~/.netrc
machine files.tecmint.lan
login tecmint
password YourStrongPassword

Here’s what each entry means:

  • machine specifies the hostname to which the credentials apply.
  • login specifies the username for that host.
  • password specifies the password, stored in plain text, making file permissions especially important.

Save the file and restrict its permissions so only your user can read and write it:

chmod 600 ~/.netrc

You can now download the file without placing credentials in the command:

wget https://files.tecmint.lan/backups/db-2026-10-25.sql.gz

For security, use HTTPS whenever possible, protect the .netrc file, and avoid committing it to version control. Although this approach keeps passwords out of command-line arguments, the credentials remain stored in plain text.

FTP downloads can also use credentials from .netrc, but classic GNU Wget and Wget2 differ in their FTP support. On Fedora 40 and later, where the wget command uses Wget2, use an FTP-capable client such as curl or lftp if FTP support is unavailable.

Pro Tips: Certificates, Defaults, and Safer Wget Downloads

A few additional habits can make Wget safer and easier to use, especially when downloading over HTTPS or running automated scripts.

Avoid using --no-check-certificate as a routine fix for certificate errors. This option disables certificate verification, making it harder to confirm that you’re connecting to the intended server. Public websites such as kernel.org should not normally require it. If Wget reports that a certificate is expired or not yet valid, check the system clock with `date` before investigating other causes.

For an internal server that uses a certificate issued by your own certificate authority (CA), configure Wget to trust that CA instead of disabling verification:

wget --ca-certificate=/etc/pki/tls/certs/tecmint-ca.crt https://192.168.122.248/repo/app.tar.gz

You can also set default options in ~/.wgetrc, which GNU Wget reads each time it runs. This avoids repeating the same flags in every command.

On Ubuntu and Debian, create the file with Nano:

nano ~/.wgetrc

On Rocky Linux, AlmaLinux, and RHEL, use Vi if Nano isn’t installed:

vi ~/.wgetrc

Add the following configuration:

# ~/.wgetrc
continue = on
tries = 10
waitretry = 30
https_only = on

Here’s what each setting does:

  • continue = on enables download resuming by default, equivalent to using -c.
  • tries = 10** sets the default number of download attempts to 10.
  • waitretry = 30 sets the maximum wait between retries to 30 seconds.
  • https_only = on restricts recursive downloads to HTTPS URLs, preventing Wget from following ordinary HTTP links during mirroring.

Save the file and exit the editor. Command-line options generally override the corresponding configuration defaults, so you can disable a default for an individual run using the appropriate option, such as --no-continue.

Keep in mind that configuration-file names and supported options can differ between GNU Wget and Wget2. If you’re using Fedora’s Wget2-based wget command, check its documentation to confirm which configuration file it reads and which settings it supports.

Conclusion

Wget can do much more than download a single file. You can rename and organize downloads, resume interrupted transfers, retry failed requests, limit bandwidth, run downloads in the background, mirror websites for offline use, and handle authentication without exposing passwords on the command line.

You also know why checking your installed version matters, especially on Fedora, where Wget2 differs from classic GNU Wget in its FTP support. For details on available options, consult man wget or wget --help.

To build your skills with other essential Linux tools, including tar, curl, grep, and tail, check out our 100+ Essential Linux Commands course for practical examples.

If you want to turn downloads into scheduled jobs with error handling, our Bash Scripting for Beginners course shows you how to build reliable scripts around commands like these.

How do you use Wget in your own setup? Do you still rely on it for scripted downloads, or have you switched to curl or Wget2?

Share your .wgetrc defaults in the comments, or post the exact error output if you’re having trouble with a download.

Two small things before you go

If something didn’t work on your setup, leave a comment and tell me which distro and version you’re on. I read every one, and most of these articles got better because a reader pointed out what was missing.

And if it did work, share it. TecMint has stayed free for 14 years because people pass these articles around, and that traffic is what pays for writing the next one.

Leave a comment
Get two free Linux courses

Learn the Linux basics with two free courses and join 34,000+ readers getting practical TecMint tutorials and selected Pro TecMint articles every week.

Pro TecMint
Get lifetime access for $99

If you want to go beyond the free tutorials, Pro gives you 18 courses, 5 ebooks, and every future course I add. One payment, lifetime access, no renewals.

Ravi Saive
Ravi Saive
Administrator
About the author

I'm Ravi Saive, an award-winning entrepreneur and founder of several successful 5-figure online businesses, including TecMint.com, GeeksMint.com, UbuntuMint.com, and the premium learning hub Pro.Tecmint.com.

10 Comments

Leave a Reply
  1. Hi,

    I need help regarding below, when T try to download website using command wget --mirror, it is going to ReadLine loop and coming out to complete request, can any one suggest on the same please.

    private void downLoadReport() {
    
    		Runtime rt = Runtime.getRuntime();
    
    		try {
    			System.out.println("InsideTRY");
    
    			Process p = rt.exec(wgetDir + "wget --mirror http://alex.smola.org/drafts/thebook.pdf");
    			// return result == 0;
    			// Process p = Runtime.getRuntime().exec("wget --mirror
    			// http://askubuntu.com");
    			System.out.println("Process " + p);
    			BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
    			String line;
    			while ((line = reader.readLine()) != null) {
    				// System.out.println(lineNumber + "\n");
    			}
    			System.out.println(line + "\n");
    
    			System.out.println("Download process is success");
    			System.out.println("Wget --mirror has been successfully executed....");
    
    		}
    
    		catch (IOException ioe) {
    			System.out.println(ioe);
    
    		} /*
    			 * catch (InterruptedException e) { // TODO Auto-generated catch
    			 * block e.printStackTrace(); }
    			 */
    
    	}
    
    Reply
  2. We are facing slowness when we are sending traffic using wget in linux machines through TCL .
    Traffic passing gets struck in the middle when the file size is more than 100MB.
    Hence we are unable to meassure the bandwidth during download.
    Please suggest any way to address this issue.

    Reply
  3. Hi…

    I want to make a script to check a website and download the latest available version of a deb file and install it.

    The problem I have is that on the website, each time the version changes, so the file name is changed, so I can not know the exact name to give the order to wget.

    I wonder if there is any way to include wildcards in wget, or similar option.

    As an example, suppose you want to download each x time the latest “Dukto” in 64 bits.

    Their website is:
    http://download.opensuse.org/repositories/home:/colomboem/xUbuntu_12.04/amd64/dukto_6.0-1_amd64.deb

    How i can tell wget to look in that directory and download the dukto*.deb?

    Thanks in advance.

    Reply
    • That means it will go through all the links on the website. So, for example, if you have a website with links to more websites then it will download each of those and any other links that are in that website. You can set the number of layers, etc (reference http://www.gnu.org/software/wget/manual/html_node/Recursive-Retrieval-Options.html ). This is actually how google works but for the whole internet, it goes through ever link on every website to every other one. Also, if you use some more commands you can actually download a whole site and make it suitable for local browsing so if you have a multipage site that you use often, you could set it recursive and then open it up even without an internet connection. I hope that makes sense(the tl;dr version is that it follows every link on that website to more links and more files in a ‘tree’)

      Reply

Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.