X
    Categories: Linux

Linux compression command utilities

1. Zip

Following are the main compression utilities that are available πŸ™‚

Format for zipping the files:Β zip <filename> <source_files>

—————————–OUTPUTβ€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”-

[root@kalwa2 zip_test]# zip test.zip test1.txt test2.txt test3.txt
adding: test1.txt (deflated 92%)
adding: test2.txt (deflated 92%)
adding: test3.txt (deflated 92%)
[root@kalwa2 zip_test]# ll
total 16
-rw-r–r–. 1 root root 221 Jun 14 09:02 test1.txt
-rw-r–r–. 1 root root 221 Jun 14 09:02 test2.txt
-rw-r–r–. 1 root root 221 Jun 14 09:03 test3.txt
-rw-r–r–. 1 root root 511 Jun 14 09:10 test.zip
[root@kalwa2 zip_test]#

—————————–END OF OUTPUTβ€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”

Β 

Format for UNzipping the files:Β unzip <filename>.zip

—————————–OUTPUTβ€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”-

[root@kalwa2 zip_test]# ll
total 16
-rw-r–r–. 1 root root 221 Jun 14 09:02 test1.txt
-rw-r–r–. 1 root root 221 Jun 14 09:02 test2.txt
-rw-r–r–. 1 root root 221 Jun 14 09:03 test3.txt
-rw-r–r–. 1 root root 511 Jun 14 09:10 test.zip
[root@kalwa2 zip_test]# rm -f *.txtΒ 

Note: Removing txt files for better understanding of the topic please do not perform this command in your environment.
[root@kalwa2 zip_test]# ll
total 4
-rw-r–r–. 1 root root 511 Jun 14 09:10 test.zip
[root@kalwa2 zip_test]# unzip test.zip
Archive: test.zip
inflating: test1.txt
inflating: test2.txt
inflating: test3.txt
[root@kalwa2 zip_test]# ll
total 16
-rw-r–r–. 1 root root 221 Jun 14 09:02 test1.txt
-rw-r–r–. 1 root root 221 Jun 14 09:02 test2.txt
-rw-r–r–. 1 root root 221 Jun 14 09:03 test3.txt
-rw-r–r–. 1 root root 511 Jun 14 09:10 test.zip
[root@kalwa2 zip_test]#

—————————–END OF OUTPUTβ€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”

Β  Β  Β  Β  Β  Β  Β  Β  Β  Β  Β  Β  Β  Β  Β  Β  Β  Β  Β  Β  Β  Β  Β  Β  Β  Β  Β  Β  Β  Β  Β  Β  Β  Β  Β  Β  Β Β 

2. gzipΒ 

Format for zipping the files: gzip

—————————–OUTPUTβ€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”-

[root@kalwa2 zip_test]# ll
total 12
-rw-r–r–. 1 root root 221 Jun 14 09:02 test1.txt
-rw-r–r–. 1 root root 221 Jun 14 09:02 test2.txt
-rw-r–r–. 1 root root 221 Jun 14 09:03 test3.txt
[root@kalwa2 zip_test]# gzip test1.txt test2.txt test3.txt
[root@kalwa2 zip_test]# ll
total 12
-rw-r–r–. 1 root root 45 Jun 14 09:02 test1.txt.gz
-rw-r–r–. 1 root root 45 Jun 14 09:02 test2.txt.gz
-rw-r–r–. 1 root root 45 Jun 14 09:03 test3.txt.gz
[root@kalwa2 zip_test]#

—————————–END OF OUTPUTβ€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”

Format for GUNzipping the files: gunzip .gz

—————————–OUTPUTβ€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”-

[root@kalwa2 zip_test]# ll
total 12
-rw-r–r–. 1 root root 45 Jun 14 09:02 test1.txt.gz
-rw-r–r–. 1 root root 45 Jun 14 09:02 test2.txt.gz
-rw-r–r–. 1 root root 45 Jun 14 09:03 test3.txt.gz
[root@kalwa2 zip_test]# gunzip test1.txt.gz
[root@kalwa2 zip_test]# ll
total 12
-rw-r–r–. 1 root root 221 Jun 14 09:02 test1.txt
-rw-r–r–. 1 root root 45 Jun 14 09:02 test2.txt.gz
-rw-r–r–. 1 root root 45 Jun 14 09:03 test3.txt.gz
[root@kalwa2 zip_test]# gunzip test2.txt.gz test3.txt.gz
[root@kalwa2 zip_test]# ll
total 12
-rw-r–r–. 1 root root 221 Jun 14 09:02 test1.txt
-rw-r–r–. 1 root root 221 Jun 14 09:02 test2.txt
-rw-r–r–. 1 root root 221 Jun 14 09:03 test3.txt
[root@kalwa2 zip_test]#

—————————–END OF OUTPUTβ€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”

3. Β bzip2Β 

Format for zipping the files: bzip2

—————————–OUTPUTβ€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”-

[root@kalwa2 zip_test]# ll
total 12
-rw-r–r–. 1 root root 221 Jun 14 09:02 test1.txt
-rw-r–r–. 1 root root 221 Jun 14 09:02 test2.txt
-rw-r–r–. 1 root root 221 Jun 14 09:03 test3.txt
[root@kalwa2 zip_test]# bzip2 test1.txt test2.txt test3.txt
[root@kalwa2 zip_test]# ll
total 12
-rw-r–r–. 1 root root 66 Jun 14 09:02 test1.txt.bz2
-rw-r–r–. 1 root root 66 Jun 14 09:02 test2.txt.bz2
-rw-r–r–. 1 root root 66 Jun 14 09:03 test3.txt.bz2

—————————–END OF OUTPUTβ€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”

Format for BUNzipping the files: bunzip2 .bz2

—————————–OUTPUTβ€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”-

[root@kalwa2 zip_test]# ll
total 12
-rw-r–r–. 1 root root 66 Jun 14 09:02 test1.txt.bz2
-rw-r–r–. 1 root root 66 Jun 14 09:02 test2.txt.bz2
-rw-r–r–. 1 root root 66 Jun 14 09:03 test3.txt.bz2
[root@kalwa2 zip_test]# bunzip2 test1.txt.bz2
[root@kalwa2 zip_test]# ll
total 12
-rw-r–r–. 1 root root 221 Jun 14 09:02 test1.txt
-rw-r–r–. 1 root root 66 Jun 14 09:02 test2.txt.bz2
-rw-r–r–. 1 root root 66 Jun 14 09:03 test3.txt.bz2
[root@kalwa2 zip_test]# bunzip2 test2.txt.bz2 test3.txt.bz2
[root@kalwa2 zip_test]# ll
total 12
-rw-r–r–. 1 root root 221 Jun 14 09:02 test1.txt
-rw-r–r–. 1 root root 221 Jun 14 09:02 test2.txt
-rw-r–r–. 1 root root 221 Jun 14 09:03 test3.txt
[root@kalwa2 zip_test]#

—————————–END OF OUTPUTβ€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”

4. Tar commands:

Format for doing the tar fromΒ Β the files:Β tar -cvf .tar

—————————–OUTPUTβ€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”-

[root@kalwa2 zip_test]# ll
total 12
-rw-r–r–. 1 root root 221 Jun 14 09:02 test1.txt
-rw-r–r–. 1 root root 221 Jun 14 09:02 test2.txt
-rw-r–r–. 1 root root 221 Jun 14 09:03 test3.txt
[root@kalwa2 zip_test]# tar -cvf test.tar test1.txt test2.txt test3.txt
test1.txt
test2.txt
test3.txt
[root@kalwa2 zip_test]# ll
total 24
-rw-r–r–. 1 root root 221 Jun 14 09:02 test1.txt
-rw-r–r–. 1 root root 221 Jun 14 09:02 test2.txt
-rw-r–r–. 1 root root 221 Jun 14 09:03 test3.txt
-rw-r–r–. 1 root root 10240 Jun 14 09:49 test.tar
[root@kalwa2 zip_test]#

—————————–END OF OUTPUTβ€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”

Β Format for doing the untar fromΒ Β the files: tar -xvf

β€”β€”β€”β€”β€”β€”β€”β€”β€”-OUTPUTβ€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”-

[root@kalwa2 zip_test]# ll
total 24
-rw-r–r–. 1 root root 221 Jun 14 09:02 test1.txt
-rw-r–r–. 1 root root 221 Jun 14 09:02 test2.txt
-rw-r–r–. 1 root root 221 Jun 14 09:03 test3.txt
-rw-r–r–. 1 root root 10240 Jun 14 09:49 test.tar
[root@kalwa2 zip_test]# rm -f *.txtΒ 

Note: Removing txt files for better understanding of the topic please do not perform this command in your environment.
[root@kalwa2 zip_test]# ll
total 12
-rw-r–r–. 1 root root 10240 Jun 14 09:49 test.tar
[root@kalwa2 zip_test]#
[root@kalwa2 zip_test]# tar -xvf test.tar
test1.txt
test2.txt
test3.txt
[root@kalwa2 zip_test]# ll
total 24
-rw-r–r–. 1 root root 221 Jun 14 09:02 test1.txt
-rw-r–r–. 1 root root 221 Jun 14 09:02 test2.txt
-rw-r–r–. 1 root root 221 Jun 14 09:03 test3.txt
-rw-r–r–. 1 root root 10240 Jun 14 09:49 test.tar
[root@kalwa2 zip_test]#

—————————–END OF OUTPUTβ€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”

For checking the contents of the tar file use commandΒ tar -tvf

β€”β€”β€”β€”β€”β€”β€”β€”β€”-OUTPUTβ€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”-

[root@kalwa2 zip_test]# tar -tvf test.tar
-rw-r–r– root/root 221 2015-06-14 09:02 test1.txt
-rw-r–r– root/root 221 2015-06-14 09:02 test2.txt
-rw-r–r– root/root 221 2015-06-14 09:03 test3.txt
[root@kalwa2 zip_test]#

—————————–END OF OUTPUTβ€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”

Β 

Related Post