9951 explained code solutions for 126 technologies


cli-tarHow do I create a .tar.gz file on Unix?


Creating a .tar.gz file on Unix can be done using the tar command.

tar -czvf <filename>.tar.gz <directory>

This command will create a .tar.gz file containing the contents of the specified directory.

  • tar: The command used to create a .tar.gz file
  • -c: The flag used to create a new archive
  • -z: The flag used to compress the archive with gzip
  • -v: The flag used to verbosely list the files being archived
  • -f: The flag used to specify the filename of the archive
  • <filename>: The filename of the archive
  • <directory>: The directory to be archived

For example, to create a .tar.gz file of the example directory, the command would be:

tar -czvf example.tar.gz example

This will create a .tar.gz file called example.tar.gz containing the contents of the example directory.

Helpful links

Edit this code on GitHub