gzip

gzip is a compression utility that is used to compress and decompress files. It is based on the DEFLATE algorithm and is used to compress files to reduce their size, thereby saving disk space and reducing the time it takes to transfer files over a network. The gzip utility is commonly used in conjunction with the tar command to create compressed archive files.

Basic Syntax

gzip [options] [target ...]

Here, options are the various flags used to specify the compression level, verbosity, and other parameters. target is the file name or list of file names to be compressed.

Commonly Used Options

  • -c: This option writes the compressed output to the standard output, allowing it to be piped to another command or written to a file.
  • -d: This option decompresses the specified file(s).
  • -f: This option forces compression or decompression even if the output file already exists.
  • -k: This option keeps the original file(s) after compression or decompression, instead of deleting them.
  • -l: This option lists the compression ratio and size of the compressed file(s).
  • -n: This option specifies the number of compression threads to be used.
  • -r: This option recursively compresses or decompresses files in subdirectories.
  • -v: This option displays verbose output.

Useful Examples

  • gzip file.txt: This compresses the file.txt file and replaces it with a compressed version of the file.
  • gzip -k file.txt: This compresses the file.txt file but keeps the original file as well.
  • gzip -d file.txt.gz: This decompresses the file.txt.gz compressed file and replaces it with the original file.
  • gzip -r folder: This recursively compresses all files in the folder directory and its subdirectories.
  • gzip -c file.txt > file.txt.gz: This compresses the file.txt file and writes the compressed output to the file.txt.gz file.
  • gzip -l file.txt.gz: This lists the compression ratio and size of the file.txt.gz compressed file.
  • gzip -vf file.txt: This compresses the file.txt file and displays verbose output.

Leave a Reply

Your email address will not be published. Required fields are marked *

Comments

  1. […] Once installed, let’s first allow TCP traffic over your SSH port so that you don’t get locked out of…

  2. […] have the option to choose between Password and SSH key selection. Learn more about SSH keys here. It’s recommended…