Can wget output to stdout?

This article provides a quick, practical guide on how to use the wget command-line utility to download a file and immediately redirect its contents to the standard output (stdout). You will learn the specific command flags required to achieve this, see real-world examples, and understand how to handle potential issues like suppressing the progress bar.

Using the -O Flag for Standard Output

By default, wget is designed to save downloaded files directly to your local disk. However, you can easily override this behavior by using the -O (uppercase letter O) option, which specifies the output document file name. Passing a hyphen (-) as the argument tells wget to stream the downloaded data directly to stdout instead of a file.

The basic syntax for the command looks like this:

wget -O - URL

Hiding the Status Log

When you pipe a file to stdout, wget will still display its download progress, status messages, and header information in the terminal. This extra data can corrupt the output if you are trying to pipe the content into another command or save it directly to a clean file.

To prevent this, you should combine the stdout flag with the -q (quiet) option. This suppresses all wget logs, ensuring that only the raw downloaded data is sent to the standard output.

wget -qO - URL

Common Practical Examples

Streaming data directly to stdout is incredibly useful for on-the-fly installations, viewing text files without saving them, or chaining commands together.

wget -qO - https://example.com/README.md
wget -qO - https://example.com/install.sh | bash
wget -qO - https://api.example.com/data.json | jq '.'