Ubuntu – What’s the difference between .tar.gz and .gz, or .tar.7z and .7z

backupcompression

Recently, I've been backing up a lot of my data, and I noticed that I can save files as .gz or .tar.gz, or .7z and .tar.7z, etcetera. What are the differences between the normal one and the .tar.* variant? Which one of them is adviced when making backups?

Best Answer

If you come from a Windows background, you may be familiar with the zip and rar formats. These are archives of multiple files compressed together.

In Unix and Unix-like systems (like Ubuntu), archiving and compression are separate.

  • tar puts multiple files into a single (tar) file.
  • gzip compresses one file (only).

So, to get a compressed archive, you combine the two, first use tar or pax to get all files into a single file (archive.tar), then gzip it (archive.tar.gz).

If you have only one file, you need to compress (notes.txt): there's no need for tar, so you just do gzip notes.txt which will result in notes.txt.gz. There are other types of compression, such as compress, bzip2 and xz which work in the same manner as gzip (apart from using different types of compression of course).