Linux compression utilities

1. Zip

Below are the main utilities that are available to compress files

Format for archiving files: zip

[[email protected] zip_test]# zip test.zip mytest1.txt mytest2.txt mytest3.txt
adding: mytest1.txt (deflated 92%)
adding: mytest2.txt (deflated 92%)
adding: mytest3.txt (deflated 92%)
[[email protected] zip_test]# ll
total 16
-rw-r–r–. 1 root root 221 Mar 19 12:12 mytest1.txt
-rw-r–r–. 1 root root 221 Mar 19 12:12 mytest2.txt
-rw-r–r–. 1 root root 221 Mar 19 12:13 mytest3.txt
-rw-r–r–. 1 root root 511 Mar 19 12:19 test.zip
[[email protected] zip_test]#

Format for unpacking files: unzip .zip

[[email protected] zip_test]# ll
total 16
-rw-r–r–. 1 root root 221 Mar 19 12:12 mytest1.txt
-rw-r–r–. 1 root root 221 Mar 19 12:12 mytest2.txt
-rw-r–r–. 1 root root 221 Mar 19 12:13 mytest3.txt
-rw-r–r–. 1 root root 511 Mar 19 12:19 test.zip
[[email protected] zip_test]# rm -f *.txt

Note: To delete text files for a better understanding of the topic, please do not run this command in your environment.

[[email protected] zip_test]# ll
total 4
-rw-r–r–. 1 root root 511 Mar 19 12:10 test.zip
[[email protected] zip_test]# unzip test.zip
Archive: test.zip
inflating: mytest1.txt
inflating: mytest2.txt
inflating: mytest3.txt
[[email protected] zip_test]# ll
total 16
-rw-r–r–. 1 root root 221 Mar 19 12:12 mytest1.txt
-rw-r–r–. 1 root root 221 Mar 19 12:12 mytest2.txt
-rw-r–r–. 1 root root 221 Mar 19 12:13 mytest3.txt
-rw-r–r–. 1 root root 511 Mar 19 12:19 test.zip
[[email protected] zip_test]#

2. gzip

Format for archiving files: gzip

[[email protected] zip_test]# ll
total 12
-rw-r–r–. 1 root root 221 Mar 19 12:12 mytest1.txt
-rw-r–r–. 1 root root 221 Mar 19 12:12 mytest2.txt
-rw-r–r–. 1 root root 221 Mar 19 12:13 mytest3.txt
[[email protected] zip_test]# gzip mytest1.txt mytest2.txt mytest3.txt
[[email protected] zip_test]# ll
total 12
-rw-r–r–. 1 root root 45 Mar 19 12:12 mytest1.txt.gz
-rw-r–r–. 1 root root 45 Mar 19 12:12 mytest2.txt.gz
-rw-r–r–. 1 root root 45 Mar 19 12:13 mytest3.txt.gz
[[email protected] zip_test]#

Format for GUNzipping files: gunzip .gz

[[email protected] zip_test]# ll
total 12
-rw-r–r–. 1 root root 45 Mar 19 12:12 mytest1.txt.gz
-rw-r–r–. 1 root root 45 Mar 19 12:12 mytest2.txt.gz
-rw-r–r–. 1 root root 45 Mar 19 12:13 mytest3.txt.gz
[[email protected] zip_test]# gunzip mytest1.txt.gz
[[email protected] zip_test]# ll
total 12
-rw-r–r–. 1 root root 221 Mar 19 12:12 mytest1.txt
-rw-r–r–. 1 root root 45 Mar 19 12:12 mytest2.txt.gz
-rw-r–r–. 1 root root 45 Mar 19 12:13 mytest3.txt.gz
[[email protected] zip_test]# gunzip mytest2.txt.gz mytest3.txt.gz
[[email protected] zip_test]# ll
total 12
-rw-r–r–. 1 root root 221 Mar 19 12:12 mytest1.txt
-rw-r–r–. 1 root root 221 Mar 19 12:12 mytest2.txt
-rw-r–r–. 1 root root 221 Mar 19 12:13 mytest3.txt
[[email protected] zip_test]#

3. bzip2

Format for archiving files with: bzip2

[[email protected] zip_test]# ll
total 12
-rw-r–r–. 1 root root 221 Mar 19 12:12 mytest1.txt
-rw-r–r–. 1 root root 221 Mar 19 12:12 mytest2.txt
-rw-r–r–. 1 root root 221 Mar 19 12:13 mytest3.txt
[[email protected] zip_test]# bzip2 mytest1.txt mytest2.txt mytest3.txt
[[email protected] zip_test]# ll
total 12
-rw-r–r–. 1 root root 66 Mar 19 12:12 mytest1.txt.bz2
-rw-r–r–. 1 root root 66 Mar 19 12:12 mytest2.txt.bz2
-rw-r–r–. 1 root root 66 Mar 19 12:13 mytest3.txt.bz2

BUNzipping file format: bunzip2 .bz2

[[email protected] zip_test]# ll
total 12
-rw-r–r–. 1 root root 66 Mar 19 12:12 mytest1.txt.bz2
-rw-r–r–. 1 root root 66 Mar 19 12:12 mytest2.txt.bz2
-rw-r–r–. 1 root root 66 Mar 19 12:13 mytest3.txt.bz2
[[email protected] zip_test]# bunzip2 mytest1.txt.bz2
[[email protected] zip_test]# ll
total 12
-rw-r–r–. 1 root root 221 Mar 19 12:12 mytest1.txt
-rw-r–r–. 1 root root 66 Mar 19 12:12 mytest2.txt.bz2
-rw-r–r–. 1 root root 66 Mar 19 12:13 mytest3.txt.bz2
[[email protected] zip_test]# bunzip2 mytest2.txt.bz2 mytest3.txt.bz2
[[email protected] zip_test]# ll
total 12
-rw-r–r–. 1 root root 221 Mar 19 12:12 mytest1.txt
-rw-r–r–. 1 root root 221 Mar 19 12:12 mytest2.txt
-rw-r–r–. 1 root root 221 Mar 19 12:13 mytest3.txt
[[email protected] zip_test]#

4. Team Tar:

Format for keeping tar from files: tar -cvf .tar

[[email protected] zip_test]# ll
total 12
-rw-r–r–. 1 root root 221 Mar 19 12:12 mytest1.txt
-rw-r–r–. 1 root root 221 Mar 19 12:12 mytest2.txt
-rw-r–r–. 1 root root 221 Mar 19 12:13 mytest3.txt
[[email protected] zip_test]# tar -cvf test.tar mytest1.txt mytest2.txt mytest3.txt
mytest1.txt
mytest2.txt
mytest3.txt
[[email protected] zip_test]# ll
total 24
-rw-r–r–. 1 root root 221 Mar 19 12:12 mytest1.txt
-rw-r–r–. 1 root root 221 Mar 19 12:12 mytest2.txt
-rw-r–r–. 1 root root 221 Mar 19 12:13 mytest3.txt
-rw-r–r–. 1 root root 10240 Mar 19 12:59 test.tar
[[email protected] zip_test]#

Format for unpacking files: tar -xvf

[[email protected] zip_test]# ll
total 24
-rw-r–r–. 1 root root 221 Mar 19 12:12 mytest1.txt
-rw-r–r–. 1 root root 221 Mar 19 12:12 mytest2.txt
-rw-r–r–. 1 root root 221 Mar 19 12:13 mytest3.txt
-rw-r–r–. 1 root root 10240 Mar 19 12:59 test.tar
[[email protected] zip_test]# rm -f *.txt

Note: deleting txt files for a better understanding of the topic, please do not run this command in your environment.

[[email protected] zip_test]# ll
total 12
-rw-r–r–. 1 root root 10240 Mar 19 12:59 test.tar
[[email protected] zip_test]#
[[email protected] zip_test]# tar -xvf test.tar
mytest1.txt
mytest2.txt
mytest3.txt
[[email protected] zip_test]# ll
total 24
-rw-r–r–. 1 root root 221 Mar 19 12:12 mytest1.txt
-rw-r–r–. 1 root root 221 Mar 19 12:12 mytest2.txt
-rw-r–r–. 1 root root 221 Mar 19 12:13 mytest3.txt
-rw-r–r–. 1 root root 10240 Mar 19 12:59 test.tar
[[email protected] zip_test]#

[[email protected] zip_test]# tar -tvf test.tar
-rw-r–r– root/root 221 2015-06-14 09:12 mytest1.txt
-rw-r–r– root/root 221 2015-06-14 09:12 mytest2.txt
-rw-r–r– root/root 221 2015-06-14 09:13 mytest3.txt
[[email protected] zip_test]#

Sidebar