Commands.page Logo

How to Download First Level Links with Wget on Ubuntu

This guide explains how to use the wget command in Ubuntu to download only the first level of links from a specific webpage. You will learn the specific flags required to limit recursion depth, ensuring you capture linked pages without downloading the entire site structure. This method is efficient for mirroring content shallowly while saving bandwidth and storage space.

Install Wget

Most Ubuntu installations come with wget pre-installed. To verify installation or install the tool if it is missing, open your terminal and run the following command:

sudo apt update
sudo apt install wget

The Core Command

To download a webpage and only follow the links found directly on that page without going deeper, use the recursive flag combined with the level flag. Execute the following command in your terminal, replacing the URL with your target website:

wget -r -l 1 https://example.com

Understanding the Flags

Complete Example

For a complete local mirror of the first level of links including assets, use this command:

wget -r -l 1 -p -k https://example.com

Important Considerations

Always respect the website’s robots.txt file and terms of service. Aggressive downloading can strain server resources. If you encounter issues, you may need to add a delay between requests using the --wait flag to reduce server load.