tar, gzip, bzip2


Overview of the most common commands when it comes to compression…


Create a tar file : tar -cpf target.tar source_folder/

Create a tar.gz file : tar -cpzf target.tar.gz source_folder/

Create a tar.bz file : tar -cpjf target.tar.bz2 source_folder/

-c : create -p : preserve permissions -z : gzip -j : bzip -f : file -x : extract -v : verbose -t : test

Extract foo.tar : tar -xvf foo.tar

Extract gzipped foo.tar.gz : tar -xvzf foo.tar.gz

Extract bzipped foo.tar.bz2 after changing directory (must exist) to bar : tar -xvjf foo.tar.bz2 -C bar/

Extract the file blah.txt from foo.tar.bz2 : tar -xvzf foo.tar.gz blah.txt

Test extraction : tar -tvzf foo.tar.gz


Extract file : gzip -d file.gz

Compress file : gzip file

Getting info from the zip file : gzip -l foo.tar.gz compressed uncompressed ratio uncompressed_name 176 10240 98.5% foo.tar


Same as gzip

Best compression : bzip2 -9 file

Thanks for reading this post!

If you found an issue in this article, you can create an issue on Github.

If you have a comment or question, please drop me a line below!