0
0
Linux-cliHow-ToBeginner · 3 min read

How to Use wget Command in Linux: Basic Syntax and Examples

The wget command in Linux downloads files from the internet using a URL. You run it by typing wget [options] URL in the terminal, which saves the file to your current folder.
📐

Syntax

The basic syntax of wget is simple and looks like this:

  • wget [options] URL

Here, URL is the web address of the file you want to download. [options] are extra commands you can add to change how wget works, like saving the file with a different name or downloading multiple files.

bash
wget [options] URL
💻

Example

This example shows how to download a file from the internet using wget. It downloads the file and saves it in your current folder with the same name as on the server.

bash
wget https://example.com/sample.txt
Output
--2024-06-01 12:00:00-- https://example.com/sample.txt Resolving example.com (example.com)... 93.184.216.34 Connecting to example.com (example.com)|93.184.216.34|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 1256 (1.2K) [text/plain] Saving to: ‘sample.txt’ sample.txt 100%[===================>] 1.23K --.-KB/s in 0s 2024-06-01 12:00:01 (12.3 MB/s) - ‘sample.txt’ saved [1256/1256]
⚠️

Common Pitfalls

Some common mistakes when using wget include:

  • Not having internet connection or wrong URL causes download failure.
  • Running wget without permissions to write in the folder will fail.
  • For large files, not using options like -c to continue interrupted downloads can waste time.

Here is a wrong and right way to continue a download:

bash
# Wrong way: restart download from beginning
wget https://example.com/largefile.zip

# Right way: continue interrupted download
wget -c https://example.com/largefile.zip
📊

Quick Reference

OptionDescription
-O filenameSave download as 'filename' instead of original name
-cContinue a partially downloaded file
-qQuiet mode, no output
-rDownload files recursively from a website
--limit-rate=amountLimit download speed (e.g., 100k, 1m)

Key Takeaways

Use wget URL to download files simply from the terminal.
Add -c to continue interrupted downloads without starting over.
Use -O filename to save the file with a custom name.
Check your internet connection and folder permissions if downloads fail.
Explore options like -r for recursive downloads and --limit-rate to control speed.