9951 explained code solutions for 126 technologies


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


To compress a file using tar and gzip, follow these steps:

  1. Create a tar file of the file or directory you want to compress:
tar -cvf <tar-file-name>.tar <file-or-directory-name>

This will create a tar file with the name you specified.

  1. Compress the tar file using gzip:
gzip <tar-file-name>.tar

This will create a gzipped tar file with the same name as the tar file, but with the .gz extension.

  1. Extract the compressed tar file:
tar -xzf <tar-file-name>.tar.gz

This will extract the contents of the gzipped tar file.

  • tar: creates a tar file of the file or directory you want to compress
  • gzip: compresses the tar file
  • tar -xzf: extracts the compressed tar file

Helpful links

Edit this code on GitHub