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 - URLHiding 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 - URLCommon 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.
- Viewing a remote text file: If you want to quickly
read a
README.mdfile hosted on GitHub without downloading it, you can pipe it directly intocatorless.
wget -qO - https://example.com/README.md- Running a remote installation script: Many modern
developer tools allow you to download and execute installation scripts
in a single terminal line by piping the
wgetoutput directly into a shell.
wget -qO - https://example.com/install.sh | bash- Passing data to another utility: You can stream a
remote dataset or API response straight into a text processing tool like
greporjq.
wget -qO - https://api.example.com/data.json | jq '.'