9951 explained code solutions for 126 technologies


cli-tarHow do I use gzip to compress myfile.tar?


  1. To compress a file myfile.tar using gzip, use the following command:
gzip myfile.tar

This will create a new compressed file myfile.tar.gz in the same directory.

  1. The gzip command uses the Lempel-Ziv (LZ77) algorithm to compress the file.
  2. The -v option can be used to get verbose output about the compression process:
gzip -v myfile.tar

Output example

myfile.tar:  78.1% -- replaced with myfile.tar.gz
  1. The -k option can be used to keep the original file after compression:
gzip -k myfile.tar
  1. The -r option can be used to recursively compress all files in a directory:
gzip -r mydirectory
  1. To decompress a file, use the gunzip command:
gunzip myfile.tar.gz
  1. For more information on the gzip command, see the GNU gzip manual.

Edit this code on GitHub