When debugging web services or testing APIs, we often need to verify server responses without cluttering our filesystem. The traditional wget
behavior of saving every download becomes counterproductive in such scenarios.
The most efficient method uses Unix's special device file:
wget http://example.com -O /dev/null
This redirects output to the null device, immediately discarding the content while still performing the full HTTP transaction.
For Windows systems or when needing response metadata:
wget -q -O - http://example.com > /dev/null
# Or for Windows:
wget -q -O NUL http://example.com
Combine with other flags for powerful testing:
# Check server headers without saving content
wget -S -O /dev/null https://api.service.com/endpoint
# Test download speed:
time wget -O /dev/null http://large.file.com/big.zip
This technique is particularly valuable for:
- CI/CD pipeline checks
- Load testing endpoints
- Monitoring service availability
- Debugging redirect chains
Be aware that:
- The request still hits the target server
- Bandwidth is still consumed
- Some servers may track HEAD differently from GET
When using wget
for web scraping, API testing, or simply checking HTTP headers, we often encounter situations where we don't actually need to save the downloaded content. The default behavior of saving files can clutter directories and waste storage space.
The simplest approach is to redirect output to standard output using -O -
:
wget -O - https://example.com > /dev/null
For cases where you only need HTTP headers (common in debugging):
wget --spider -S https://example.com 2>&1 | grep '^ HTTP'
This command:
- Uses
--spider
for a "dry run" -S
shows server response- Redirects stderr to stdout for processing
Pipe wget output directly to processing tools without intermediate files:
wget -qO - https://api.example.com/data.json | jq '.results[0]'
For quick network latency checks while discarding content:
time wget -O /dev/null https://example.com
Remember that:
- The
-q
flag suppresses output for cleaner scripts - Combining with
--limit-rate
prevents bandwidth hogging - Some servers may block repeated requests
For simpler discard operations, curl
might be more straightforward:
curl -s -o /dev/null https://example.com