1

I usually create a tgz file for my_files with the command tar -czvf my_files.tgz my_files, and extract them with tar -zxvf my_files.tgz. Now I have a tar file created with the command tar -cvf my_files.tar my_files. I'm wondering how I can turn the my_files.tar into my_files.tgz so that later I can extract it with the command tar -zxvf my_files.tgz? Thanks.

4

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.

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.