bzip2

to compress and decompress files

Examples

compress files (original file will be removed after compression)

bzip2 myfile.txt

bzip2 *.txt

keep the original file (option -k)

bzip2 -k myfile.txt

as pipe

bzip2 -c myfile.txt > myfile.txt.bz2

extract/decompress

to view the compressed file (decompress to standard output), original file keeps unchanged

bzcat myfile.txt.bz2

to decompress .bz2 files, use option -d (.bz2 file will be removed)

bzip2 -d myfile.txt.bz2

more bz commands

bzgrep, bzcmp, bzdiff, bzcat, bzless, bzmore

Seq-Examples

compress all .fastq files

bzip2 *.fastq

to view the first 20 lines of a bzip2 compressed .fastq file

bzcat sample.fastq.bz2 | head -20

tar.bz2

compress all files of a directory in one compressed .tar.bz2 archive-file (option -j for bzip2 compression)

tar -jvcf compressedFiles.tar.bz2 directory_orig_files/ # -j for bz2

tar -zcvf compressedFiles.tar.gz directory_orig_files/ # -z for gzip

compress a set of files (without directory)

tar -jvcf compressedFiles.tar.bz2 file1.txt file2.txt file3.txt

tar -jvcf compressedFiles.tar.bz2 *.txt

join paired read sequence files into a single compressed sample file

tar -jvcf sample.tar.bz2 sample_1.fastq sample_2.fastq

decompress .tar.bz2 files

tar -jvxf sample.tar.bz2

to decompress in a pipe, extract files to standard output (option -O)

tar -jxOf sample.tar.bz2 | head -20 # views the first 20 lines

list content (all files) of a .tar.bz2 archive

tar -tf sample.tar.bz2

sample_1.fastq

sample_2.fastq

extract single file from .tar.bz2 archive

tar -jvxf sample.tar.bz2 sample_1.fastq

sample_1.fastq

see also:

→ www.bzip.org

→ gzip