Wednesday, April 10, 2019

UNIX bzip2 command with examples

Create a bz2 archive

To create a bzip2 archive simply specify the name of the file to compress. bzip2 will create an archive with the name of the file. One note to remember is that bzip2 will delete the input file being compressed. So you need to specify the ‘-k’ option which tells bzip2 to keep the input file

bzip2 filename.ext
sam@asus:~/unix% bzip2 -k 5MB.zip 
sam@asus:~/unix% ls -l 5MB.zip.bz2 
-rw-rw-r-- 1 sam sam 5265879 Jun  2  2008 5MB.zip.bz2
sam@asus:~/unix% 

Decompress or extract a bz2 archive

To decompress a bz2 archive we can use the ‘-d’ option which tells bzip2 to decompress the archive. By default bzip2 does not overwrite files, so to remedy that you can use the ‘-f’ option to tell bzip2 to overwrite already existing files.

bzip2 -d file.ext
sam@asus:~/unix% bzip2 -d 5MB.zip.bz2 
bzip2: Output file 5MB.zip already exists.
sam@asus:~/unix% bzip2 -df 5MB.zip.bz2 
sam@asus:~/unix% 

Set verbose output

bzip2 gives you the option to see verbose output to the screen with the ‘-v’ option. The more ‘-v’s added the more verbose bzip2 will be. The ‘v’ option can be combined with any of the other options bzip2 allows.

bzip2 -v, bzip2 -vv, ...
sam@asus:~/unix% bzip2 -k 5MB.zip 
sam@asus:~/unix% bzip2 -vdf 5MB.zip.bz2 
  5MB.zip.bz2: done
sam@asus:~/unix% bzip2 -k 5MB.zip 
sam@asus:~/unix% bzip2 -vvvdf 5MB.zip.bz2 
  5MB.zip.bz2: 
    [1: huff+mtf rt+rld {0xc782e51c, 0xc782e51c}]
    [2: huff+mtf rt+rld {0x76d1a985, 0x76d1a985}]
    [3: huff+mtf rt+rld {0x27d0b28b, 0x27d0b28b}]
    [4: huff+mtf rt+rld {0xacdf1819, 0xacdf1819}]
    [5: huff+mtf rt+rld {0x05d74b5d, 0x05d74b5d}]
    [6: huff+mtf rt+rld {0x697e0b4a, 0x697e0b4a}]
    combined CRCs: stored = 0x726f5200, computed = 0x726f5200
    done
sam@asus:~/unix% 

Test the integrity of a bz2 archive

To test the integrity of an archive you would use the ‘-t’ option.

bzip2 -vvt file.bz2
sam@asus:~/unix% bzip2 -k 5MB.zip 
sam@asus:~/unix% bzip2 -vvt 5MB.zip.bz2 
  5MB.zip.bz2: 
    [1: huff+mtf rt+rld]
    [2: huff+mtf rt+rld]
    [3: huff+mtf rt+rld]
    [4: huff+mtf rt+rld]
    [5: huff+mtf rt+rld]
    [6: huff+mtf rt+rld]
    ok
sam@asus:~/unix% 

No comments:

Post a Comment

Exploiting Weak WEBDAV Configurations

The server we are going to audit has the following fingerprint. 80/tcp open http Apache httpd 2.2.8 ((Ubuntu) DAV/2) Next we need t...