Create .tar.gz File in Linux

Last updated on Dec 27, 2019 in Linux

When you create a .tar.gz file, you usually want to compress an entire folder. This can be done with a simple command using tar with gzip compression.

Let’s assume your folder is named folder. Type following command in terminal:

$ tar -zcvf folder.tar.gz folder/
  • z uses gzip as a compression method to the tar archive
  • c creates a new archive file
  • v verbose output
  • f we enter the new filename for the archive after this parameter

To verify that the contents of the newly created folder.tar.gz, you can enter:

$ tar -tf folder.tar.gz

This should output the contents of the folder.