9951 explained code solutions for 126 technologies


cli-tarHow do I compress a single file using tar and gzip?


Compressing a single file using tar and gzip requires two steps:

  1. Create a tar file containing the file to be compressed:
tar -cf <file_name>.tar <file_to_compress>

This command will create a tar file named <file_name>.tar containing the file <file_to_compress>.

  1. Compress the tar file using gzip:
gzip <file_name>.tar

This command will compress the tar file, creating a file named <file_name>.tar.gz.

The resulting <file_name>.tar.gz file is the compressed version of the original file.

Code explanation

  • tar -cf <file_name>.tar <file_to_compress>: creates a tar file containing the file to be compressed
  • gzip <file_name>.tar: compresses the tar file using gzip

Helpful links

Edit this code on GitHub