Skip to main content
Mention that z isn't necessary on extraction.
Source Link
Stephen Kitt
  • 482.9k
  • 60
  • 1.2k
  • 1.4k

A plain .tar archive created with cf (with or without v) is uncompressed; to get a .tar.gz or .tgz archive, compress it:

gzip < my_files.tar > my_files.tgz 

You might want to add -9 for better compression:

gzip -9 < my_files.tar > my_files.tgz 

Both variants will leave both archives around; you can use

gzip -9 my_files.tar 

instead, which will produce my_files.tar.gz and delete my_files.tar (if everything goes well). You can then rename my_files.tar.gz to my_files.tgz if you wish.

With many tar implementations you can extract archives without specifying the z option, and tar will figure out what to do — so you can use the same command with compressed and uncompressed archives.

A plain .tar archive created with cf (with or without v) is uncompressed; to get a .tar.gz or .tgz archive, compress it:

gzip < my_files.tar > my_files.tgz 

You might want to add -9 for better compression:

gzip -9 < my_files.tar > my_files.tgz 

Both variants will leave both archives around; you can use

gzip -9 my_files.tar 

instead, which will produce my_files.tar.gz and delete my_files.tar (if everything goes well). You can then rename my_files.tar.gz to my_files.tgz if you wish.

A plain .tar archive created with cf (with or without v) is uncompressed; to get a .tar.gz or .tgz archive, compress it:

gzip < my_files.tar > my_files.tgz 

You might want to add -9 for better compression:

gzip -9 < my_files.tar > my_files.tgz 

Both variants will leave both archives around; you can use

gzip -9 my_files.tar 

instead, which will produce my_files.tar.gz and delete my_files.tar (if everything goes well). You can then rename my_files.tar.gz to my_files.tgz if you wish.

With many tar implementations you can extract archives without specifying the z option, and tar will figure out what to do — so you can use the same command with compressed and uncompressed archives.

Source Link
Stephen Kitt
  • 482.9k
  • 60
  • 1.2k
  • 1.4k

A plain .tar archive created with cf (with or without v) is uncompressed; to get a .tar.gz or .tgz archive, compress it:

gzip < my_files.tar > my_files.tgz 

You might want to add -9 for better compression:

gzip -9 < my_files.tar > my_files.tgz 

Both variants will leave both archives around; you can use

gzip -9 my_files.tar 

instead, which will produce my_files.tar.gz and delete my_files.tar (if everything goes well). You can then rename my_files.tar.gz to my_files.tgz if you wish.