Linux gzip command

The gzip command in Linux is used to compress files and reduce their size. It is commonly used to compress single files, creating files with the extension “.gz”.

Here’s an overview of how to use the gzip command:

  1. Basic Usage:
    To compress a file using gzip, simply type gzip followed by the name of the file you want to compress. For example:
   gzip file.txt

This command will compress file.txt and create a compressed file named file.txt.gz.

  1. Decompressing Files:
    To decompress a compressed file, you can use the gunzip command or simply the gzip command with the -d option. For example:
   gunzip file.txt.gz

or

   gzip -d file.txt.gz

Both commands will decompress the file file.txt.gz and restore it to its original form as file.txt.

  1. Keeping the Original File:
    By default, gzip replaces the original file with the compressed file. If you want to keep the original file while creating a compressed version, you can use the -c option to send the compressed output to the standard output and redirect it to a new file. For example:
   gzip -c file.txt > file.txt.gz

This command compresses file.txt and creates a compressed file named file.txt.gz, while preserving the original file.

  1. Examples:
  • Compressing a file: gzip file.txt This command compresses file.txt and creates a compressed file named file.txt.gz.
  • Decompressing a file: gunzip file.txt.gz or gzip -d file.txt.gz Both commands decompress the file file.txt.gz and restore it to its original form.
  • Compressing a file and keeping the original:
    gzip -c file.txt > file.txt.gz
    This command compresses file.txt and creates a compressed file named file.txt.gz, while preserving the original file.

The gzip command is widely used for compressing files in Linux. It helps reduce file sizes, making them easier to store and transfer. Compressed files can be decompressed using the gunzip command or by using gzip with the -d option.

For more information about the gzip command and its options, you can refer to the manual page by typing man gzip in your terminal.