Commands.page Logo

How to Decompress Gzip Data from Stdin on Ubuntu

This article explains the specific command used to decompress gzip data streams from standard input within the Ubuntu Linux environment. It covers the primary utility flags required for pipeline operations and provides practical examples for immediate use.

The Primary Command

The command used to decompress a stream of gzip data from stdin is gunzip -c. You can also use zcat, which functions similarly for this purpose. These tools read compressed data from standard input and write the decompressed output to standard output, allowing you to chain commands together in a pipeline.

Usage Examples

To decompress a file passed through stdin and save the result to a new file, use the following syntax:

cat example.gz | gunzip -c > example

In this example, cat sends the compressed file to stdin, gunzip -c decompresses the stream, and the > redirect saves the output. You can omit the cat command by passing the file directly to gunzip, but using the pipe explicitly demonstrates stdin handling.

Using Zcat as an Alternative

The zcat command is often preferred for viewing compressed files without creating new files. It reads from stdin if no file is specified or if used in a pipeline:

cat example.gz | zcat

This prints the decompressed content directly to your terminal. Both gunzip -c and zcat are pre-installed on standard Ubuntu systems and require no additional configuration.