Linux bzip2 Command examples
“bzip2” is one of the compression method in linux,
high-quality data compressor. It typically compresses files to within
10% to 15% of the best available techniques (the PPM family of
statistical compressors) It compresses the normal file and stored in
single .bz2 extension file, this compression is much better compared to
bzip2 compression.
Syntax:
Common syntax for bzip2 and bunzip2.# bzip2 (Compress) syntax #
root@2daygeek [~]# bzip2 [file to be compressed]
# bzip2 (Decompress) syntax #
root@2daygeek [~]# bunzip2 [.bz2 file name]
# bzip2 (Decompress) syntax #
root@2daygeek [~]# bzip2 -d [.bz2 file name]
1) How to compress the file using bzip2 command
The below example compress the “test-bzip2.txt” file to test-bzip2.txt.bz2 file. See the output.# bzip2 test-bzip2.txtHere i’m going to check the mentioned file was compressed or not. See the output.
# ll -h
total 56K
drwx------. 6 mageshm mageshm 4.0K Dec 31 09:00 ./
drwx--x--x. 16 root root 4.0K Dec 24 01:16 ../
-rw-------. 1 mageshm mageshm 1.3K Dec 27 15:05 .bash_history
-rw-r--r--. 1 mageshm mageshm 18 May 10 2012 .bash_logout
-rw-r--r--. 1 mageshm mageshm 176 May 10 2012 .bash_profile
-rw-r--r--. 1 mageshm mageshm 124 May 10 2012 .bashrc
-rw-r--r--. 1 root root 26 Dec 27 12:25 liks
drwxr-xr-x. 3 mageshm mageshm 4.0K Dec 31 08:54 links/
drwxrwxr-x. 2 mageshm mageshm 4.0K Nov 16 10:14 perl5/
drwxr-xr-x. 2 mageshm mageshm 4.0K Nov 16 10:07 public_ftp/
drwxr-xr-x. 3 mageshm mageshm 4.0K Nov 16 10:07 public_html/
lrwxrwxrwx. 1 root root 31 Dec 7 09:41 s-link-file -> /links/soft-link/test-soft-link
lrwxrwxrwx. 1 root root 38 Dec 7 09:42 s-link-folder -> /links/soft-link/test-soft-link-folder
-rw-r--r--. 1 root root 61 Dec 27 13:35 test2-bzip2.txt
-rw-r--r--. 1 root root 61 Dec 31 08:54 test3-bzip2.txt
-rw-r--r--. 1 root root 92 Dec 27 13:31 test-bzip2.txt.bz2
2) How to Unzip/de-compress the bzip2 file
The below command is Unzip/de-compress the bzip2 file. See the below output.# bunzip2 test-bzip2.txt.bz2 or # bzip2 -d test-bzip2.txt.bz2Here i’m going to check the file whether de-compressed or not. see the output.
# ll -h
total 56K
drwx------. 6 mageshm mageshm 4.0K Dec 31 09:11 ./
drwx--x--x. 16 root root 4.0K Dec 24 01:16 ../
-rw-------. 1 mageshm mageshm 1.3K Dec 27 15:05 .bash_history
-rw-r--r--. 1 mageshm mageshm 18 May 10 2012 .bash_logout
-rw-r--r--. 1 mageshm mageshm 176 May 10 2012 .bash_profile
-rw-r--r--. 1 mageshm mageshm 124 May 10 2012 .bashrc
-rw-r--r--. 1 root root 26 Dec 27 12:25 liks
drwxr-xr-x. 3 mageshm mageshm 4.0K Dec 31 08:54 links/
drwxrwxr-x. 2 mageshm mageshm 4.0K Nov 16 10:14 perl5/
drwxr-xr-x. 2 mageshm mageshm 4.0K Nov 16 10:07 public_ftp/
drwxr-xr-x. 3 mageshm mageshm 4.0K Nov 16 10:07 public_html/
lrwxrwxrwx. 1 root root 31 Dec 7 09:41 s-link-file -> /links/soft-link/test-soft-link
lrwxrwxrwx. 1 root root 38 Dec 7 09:42 s-link-folder -> /links/soft-link/test-soft-link-folder
-rw-r--r--. 1 root root 61 Dec 27 13:35 test2-bzip2.txt
-rw-r--r--. 1 root root 61 Dec 31 08:54 test3-bzip2.txt
-rw-r--r--. 1 root root 60 Dec 27 13:31 test-bzip2.txt
Comments
Post a Comment