63

I want to compress files in .tgz. I know how to make tar.gz(with tar and gzip) and some people say it is almost the same, but I need to make a .tgz, how??

1
  • You might be interested in .7z and .xz which are great. – Anonymous Nov 30 '11 at 0:07
89

A tar.gz file and a .tgz file are similar.

Compress files using tar:

tar -cvzf <name of tarball>.tgz /path/to/source/folder

for example, I want to create a backup.tgz or backup.tar.gz from folder /home/user/project

tar -cvzf backup.tgz /home/user/project

tar -cvzf backup.tar.gz /home/user/project

You can use tar cvzf instead of tar -cvzf as well.

Extract .tgz or .tar.gz files using tar

tar -xvzf backup.tgz

tar -xvzf backup.tar.gz

Mnemonic for compression (the order of the flags do not matter)

  • C ompress
  • Z ee
  • F ile
  • V erbose

Mnemonic for extraction (the order of the flags do not matter)

  • e X tract
  • Z ee
  • F ile
  • V erbose
5
  • Is there a flag to have a password when you compress your file? – Dorian Dore Apr 17 '15 at 4:04
  • 3
    Nitpick: the order of the flags does matter for f: it must be the last flag, otherwise it fails. – Andres F. Jul 25 '17 at 14:41
  • 7
    For the flags, c is better remembered as create, and z is remembered as compression, as in the z from zlib, gzip, zip. A better mnemonic would be C reate Z ipped F ile. – spencer7593 Oct 31 '17 at 20:18
  • Aren't .tar.gz file and a .tgz exactly the same? – Immanuel Weihnachten Apr 22 '20 at 9:42
  • @ImmanuelWeihnachten these are just file extensions without any explicit meaning. You give meaning to them. And yes, .tar.gz and a .tgz considered the same. – Neurotransmitter Jun 8 '20 at 12:32
12

It's the same. Just rename the file from file.tar.gz to file.tgz.

1
  • 7
    You've forgotten the command for renaming a file: mv file.tar.gz file.tgz. Obvious, but worth mentioning – Lekensteyn Nov 29 '11 at 23:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.