Commands.page Logo

Wget Option to Convert Links for Local Viewing on Ubuntu

This article explains how to configure the wget command line utility on Ubuntu to download websites for offline browsing. It focuses specifically on the flag required to adjust hyperlinks within downloaded HTML files so they point to local resources instead of remote URLs. By using this method, users can navigate mirrored sites without an internet connection.

The option that allows wget to convert links in downloaded HTML files for local viewing is -k or its long form --convert-links. When you use this flag, wget modifies the links in the saved HTML documents after the download is complete. It changes absolute links, which point to the original website, into relative links that point to the files you just downloaded on your local hard drive.

How to Use the Command

To download a webpage and make it suitable for local browsing, run the following command in your Ubuntu terminal:

wget -k [URL]

Replace [URL] with the specific web address you wish to mirror. For a more complete offline experience, it is common to combine this option with -p (page requisites). This ensures that all necessary images, CSS, and scripts are downloaded alongside the HTML file.

wget -kp [URL]

Why This Is Necessary

Without the convert links option, clicking a link in your downloaded HTML file will attempt to open the live version on the internet. If you are offline, these links will fail. Using -k ensures that your browser looks for the content within your local directory structure, allowing for seamless navigation through the downloaded site without requiring an active network connection.