wget
Name
Wget - The non-interactive network downloader.
Purpose
Download files over a network.
You can use it to download files over private networks like your home, school, or work network.
You can use it to download files over public networks like the internet.
Note
You will only be seeing examples of downloading files over the internet.
Usage
wget [url]Using wget you can download the file using its unique URL. The downloaded file can be any format.
Some examples:
- HTML File: .html
- Debian Package File: .deb
- Comma Separated Values: .csv
- Python: .py
- Shell: .sh
- Zipped Directory: .zip
- Archived Directory: .tar.gz
- Image: .png,.jpeg,.jpg
- etc…
Example
Make a wget request for the file at https://www.launchcode.org:
wget https://www.launchcode.orgResults:
After making the wget request you can see a new file was downloaded and exists in the pictured user’s home directory: index.html.
Bonus
You can explore the contents of the newly downloaded index.html with the cat command.
Practice Files
For your convenience we have provided files for you to practice on directly with this curriculum.
By hovering over the files you can see the URL of the specific resource, in the bottom left corner of your web browser.
The url from the picture above is: localhost:1313/userspace-applications/walkthrough/wget/_index.files/hello.py
Warning
The URL has the following format: protocol://domain/path to future proof this curriculum we will simply provide the path to each of the files, you will be responsible for providing the protocol & domain. So the example picture from above would be: /userspace-applications/walkthrough/wget/_index.files/hello.py, however you would need to add the protocol, and domain before executing the command.
Download hello.txt
Craft a wget request to download the hello.txt file:
wget [protocol]://[domain]/userspace-applications/walkthrough/wget/_index.files/hello.txtCommand output:
Validation
Check the contents of the downloaded file with cat:
cat hello.txtCommand output:
Download hello.sh
Craft a wget request to download the hello.sh file:
wget [protocol]://[domain]/userspace-applications/walkthrough/wget/_index.files/hello.shCommand output:
Validation
Check the contents of the downloaded file with cat:
cat hello.shCommand output:
This file happens to be a bash script that you can execute with the bash command:
bash hello.shCommand output:
Download hello.py
Craft a wget request to download the hello.py file:
wget [protocol]://[domain]/userspace-applications/walkthrough/wget/_index.files/hello.py`Command output:
Validation
Check the contents of the downloaded file with cat:
cat hello.pyThis file happens to be a python script that you can execute with the python3 interpreter:
python3 hello.pyCommand output:
Download roster.csv
Craft a wget request to download the roster.csv file:
wget [protocol]://[domain]/userspace-applications/walkthrough/wget/_index.files/roster.csvCommand output:
Validation
Check the contents of the file with cat:
cat roster.csvOutside Example (Imgur)
Let’s find the link for a grumpy cat photo: https://imgur.com/gallery/Xl0W2iX
, open dev tools, find src= of the image which is: https://i.imgur.com/Xl0W2iX.jpeg.
Let’s request that specific file with wget.
wget https://i.imgur.com/Xl0W2iX.jpegValidation
wget downloaded a file named Xl0W2iX.jpeg, let’s open it in Firefox and see the photo.
Note
To open a file in Firefox, first open the browser, then hit ctrl + o to open a new file, then select the file you just downloaded in your home directory: Xl0W2iX.jpeg.
Recap
We can use the wget tool to download files from the internet.













