Skip to content

/commands/wget/wget-download-list-of-files

wget -i urls.txt: download a list of URLs from a file

The commands on this page have not been executed by our verification runner yet.updated
tool
wget
versions
GNU Wget 1.x
os
linux, macos, windows

wget -i urls.txt downloads every URL listed in urls.txt, one URL per line, in order. Combine it with -P DIR to save the files into a directory, -nc to skip files that already exist (so the command can be re-run after an interruption), and -c to resume partial downloads. URLs given on the command line as well are fetched first. With -i -, wget reads the list from standard input.

Commands

bash
# urls.txt: one URL per line
cat > urls.txt <<'EOF'
https://example.com/data/2026-01.csv
https://example.com/data/2026-02.csv
https://example.com/data/2026-03.csv
EOF

# Download all of them into ./data, skip files already present
wget -nc -P data -i urls.txt

# Resume partial files, wait 1 s between requests, log to a file
wget -c --wait=1 -o wget.log -P data -i urls.txt

# URLs from another command
grep -o 'https://[^"]*\.pdf' page.html | sort -u | wget -nc -P pdfs -i -

example.com stands for the real server. Keep the list free of empty lines with spaces, and make sure each line is a complete URL.

Options for batch downloads

OptionEffect
-i FILE, --input-file=FILERead URLs from FILE; - means standard input
-B URL, --base=URLResolve relative links in the input file against URL
-F, --force-htmlTreat the input file as HTML and download the links it contains
-ncSkip URLs whose file already exists
-cResume partial files
-P DIRSave all files under DIR
--wait=SECONDSPause between requests, to be gentle with the server
--random-waitVary the pause between 0.5 and 1.5 times --wait
-t N, --tries=NNumber of attempts per URL (default 20)
-o LOG / -a LOGWrite or append the log to LOG instead of the terminal
-nv, --no-verboseOne line per file in the log

Exit status after a batch

CodeMeaning
0No problems
1Generic error
2Parse error, for example a bad option or input file
3File I/O error
4Network failure
5SSL verification failure
6Username or password authentication failure
7Protocol error
8Server issued an error response, such as 404 or 403

When several kinds of error occur in one run, the lower-numbered code wins (0 and 1 excepted), as the manual states. A batch with one 404 among a hundred successes still exits 8, and the log shows which URL failed.

Pitfalls

  • Windows line endings. A list saved with CRLF endings can make wget request URLs ending in %0D and get 404 errors. Convert it with dos2unix urls.txt or tr -d '\r'.
  • Duplicate names. Two URLs ending in the same file name (.../a/data.csv, .../b/data.csv) give data.csv and data.csv.1, or with -nc the second is skipped. Use -x to keep the directory structure.
  • Rate limits. Servers may answer 429 or 403 to fast batches; add --wait.
  • PowerShell 5.1 maps wget to Invoke-WebRequest; use wget.exe.

Check the result

Count the downloaded files against the list: wc -l < urls.txt and ls data | wc -l. With -nv -o wget.log, grep -c ERROR wget.log counts the failures.

FAQ

Can I read the URLs from standard input?

Yes, use - as the file name, for example grep '\.pdf$' links.txt | wget -i -. To read a file that is literally named -, write ./-.

How do I download the files in parallel?

GNU Wget 1.x downloads one file at a time. Split the work with xargs, for example xargs -n 1 -P 4 wget -q -nc < urls.txt, which runs four wget processes, or use a tool designed for parallel transfers.

How do I see which URLs failed?

Write a log with -o wget.log (or -a to append) and search it for ERROR lines. wget's exit status reports only the most serious error of the whole run, not which URLs it affected.

Sources