What Does the Mirror Flag Do in wget?

The wget command-line tool is a popular utility for downloading files from the web, and its mirror flag (-m or --mirror) is the ultimate shortcut for backing up or duplicating entire websites. This flag acts as a master switch that enables a specific combination of options designed to systematically crawl a site and download all of its assets. By understanding how the mirror flag works and combining it with a few other essential parameters, you can efficiently create offline archives of web pages while respecting server resources.

The Anatomy of the Mirror Flag

When you use -m or --mirror in a wget command, you aren’t just turning on a single feature. Instead, wget automatically activates a bundle of four distinct settings optimized for website replication:

In practice, running wget -m https://example.com is identical to running wget -r -l inf -N --no-remove-listing https://example.com, but much easier to type and remember.

Crucial Companion Flags for Local Browsing

If your goal is to download a website so you can browse it offline on your local computer, simply using -m is often not enough. Website links will still point to the live internet URL (e.g., https://example.com/about) rather than your local files. To fix this, you should combine the mirror flag with a few other options:

wget -m -k -p -E https://example.com

Here is what those additional flags do to make your mirrored site fully functional offline:

Best Practices and Server Etiquette

Mirroring a website can put a heavy load on the host server because wget requests pages much faster than a human browsing the site would. To avoid getting your IP address banned or accidentally crashing a small server, it is highly recommended to introduce a delay between requests using the -w or --wait flag.

For example, adding -w 2 tells wget to wait two seconds between every file it downloads. You can also use --random-wait to vary the delay between 0.5 and 1.5 times your specified wait time, making the traffic pattern look more natural to server firewalls.