tar gz is better for Linux/Unix as it retains permissions, such as “executable” on scripts.

tar.gz

  • Stores unix file attributes: uid, gid, permissions (most notably executable). The default may depend on your distribution, and can be toggled with options.
  • Consolidates all files to be archived in one file (“Tape ARchive”).
  • Actual compression is done by GZIP, on the one .tar file

zip

  • Stores MSDOS attributes. (Archive, Readonly, Hidden, System)
  • Compresses each file individually, then consolidates the individually compressed files in one file
  • Includes a file table at the end of the file

Because zip compresses the files individually, a zip-archive will most-likely have a larger size (especially with many smaller files – think config files).

Unlike zipgzip functions as a compression algorithm only.

Because of various reasons some of which hearken back to the era of tape drives, Unix uses a program named tar to archive data, which can then be compressed with a compression program like gzipbzip27zip, etc.

In order to “zip” a directory, the correct command would be

tar -zcvf archive.tar.gz directory/ 

This will tell tar to

  • compress it using the z (gzip) algorithm
  • c (create) an archive from the files in directory (tar is recursive by default)
  • v (verbosely) list (on /dev/stderr so it doesn’t affect piped commands) all the files it adds to the archive.
  • and store the output as a f (file) named archive.tar.gz

The tar command offers gzip support (via the -z flag) purely for your convenience. The gzip command/lib is completely separate. The command above is effectively the same as

tar -cv directory | gzip > archive.tar.gz

To decompress and unpack the archive into the current directory you would use

tar -zxvf archive.tar.gz

That command is effectively the same as

gunzip < archive.tar.gz | tar -xv

tar has many, many, MANY other options and uses as well; I heartily recommend reading through its manpage sometime.

src:

https://unix.stackexchange.com/questions/93139/can-i-zip-an-entire-folder-using-gzip

https://superuser.com/questions/146754/on-linux-unix-does-tar-gz-versus-zip-matter

https://unix.stackexchange.com/questions/320240/zip-the-entire-server-from-command-line

https://help.ubuntu.com/community/BackupYourSystem/TAR

0
Would love your thoughts, please comment.x
()
x