compression commands in linux

31
Compression Commands in Linux Pegah Taheri

Upload: pegah-taheri

Post on 09-Jul-2015

279 views

Category:

Education


4 download

TRANSCRIPT

Page 1: Compression Commands in Linux

Compression Commands in

LinuxPegah Taheri

Page 2: Compression Commands in Linux

Linux / Unix Command: gzip

Page 3: Compression Commands in Linux

Linux / Unix Command: gzip

• gzip is a fast and efficient compression program– .gz filename extension– gzip test.txt

• By default, gzip keeps the original file name and timestamp in the compressed file.

Page 4: Compression Commands in Linux

gzip Synopsis

• gzip [ -acdfhlLnNrtvV19 ] [-S suffix] [ name ... ]

• gunzip [ -acfhlLnNrtvV ] [-S suffix] [ name ... ] • zcat [ -fhLV ] [ name ... ]

• gunzip also recognizes the special extensions .tgz and .taz as shorthands for .tar.gz and .tar.Z respectively.

Page 5: Compression Commands in Linux

gzip OPTIONS

• -c --stdout --to-stdout– Write output on standard output– keeps original files unchanged. – If there are several input files, the output

consists of a sequence of independently compressed members

• -f –force– Force compression or decompression even if

the file has multiple links or the corresponding file already exists

Page 6: Compression Commands in Linux

gzip OPTIONS

• -l –list– For each compressed file, list the following

fields:• compressed size: size of the compressed file

• uncompressed size: size of the uncompressed file

• ratio: compression ratio (0.0% if unknown) • uncompressed_name: name of the uncompressed

file

Page 7: Compression Commands in Linux

• -n --no-name– When compressing, do not save the original file

name and time stamp by default.– When decompressing, do not restore the original

file name if present (remove only the gzip suffix from the compressed file name) and do not restore the original time stamp if present.

• -N –name– When compressing, always save the original file

name and time stamp

– this is the default!

gzip OPTIONS

Page 8: Compression Commands in Linux

• -r –recursive– Travel the directory structure recursively

• -t –test– Test : Check the compressed file integrity.

gzip OPTIONS

Page 9: Compression Commands in Linux

• -# --fast –best– Regulate the speed of compression using the

specified digit # • -1 or --fast

– indicates the fastest compression method – less compression

• -9 or --best – indicates the slowest compression method

– best compression

• The default compression level is-6 • That is, biased towards high compression at

expense of speed

gzip OPTIONS

Page 10: Compression Commands in Linux

gzip decompression

• Compressed files can be restored to their original form using:– gzip -d oror– gunzip oror– zcat

• gunzip can currently decompress files created by gzip, zip, compress, compress -H or pack. – The detection of the input format is automatic.

Page 11: Compression Commands in Linux

• gzip and gunzip can also compress or decompress data from standard input and output– ls -laR $HOME | gzip > filelist.gz– Or by using –c option

gzip decompression

Page 12: Compression Commands in Linux

Linux / Unix Command: bzip2

Page 13: Compression Commands in Linux

bzip2

• bzip2, bunzip2 – a block-sorting file compressor, v1.0.2

• bzcat – decompresses files to stdout

• bzip2recover – recovers data from damaged bzip2 files

Page 14: Compression Commands in Linux

• on the average about 10-20% better than gzip– at the expense of longer compression times

• Output with .bz2 filename extension

bzip2

Page 15: Compression Commands in Linux

• bzip2 [ -cdfkqstvzVL123456789 ] [ filenames ... ] • bunzip2 [ -fkvsVL ] [ filenames ... ] • bzcat [ -s ] [ filenames ... ]

• bzip2recover filename

• Each file is replaced by a compressed version of itself, with the name "original_name.bz2“

bzip2: SYNOPSIS

Page 16: Compression Commands in Linux

• -c –stdout– (as in gzip) Compress or decompress to

standard output.

• -t –test– Check integrity of the specified file(s), but

don't decompress them. • This really performs a trial decompression and

throws away the result.

bzip2 OPTIONS

Page 17: Compression Commands in Linux

• -k –keep– Keep (don't delete) input files during

compression or decompression.

• -s –small– Reduce memory usage, for compression,

decompression and testing.

• -1 (or --fast) to -9 (or --best)– Set the block size to 100 k, 200 k .. 900 k

when compressing.– Has no effect when decompressing.

bzip2 OPTIONS

Page 18: Compression Commands in Linux

• bzcat • decompresses files to stdout

• bunzip2

• Cannot use bunzip2 to uncompress files compressed with gzip and vice versa

bzip2 decompression

Page 19: Compression Commands in Linux

• bzip2 -d – decompresses all specified files.– Files which were not created by bzip2 will be

detected and ignored• warning issued.

bzip2 decompression

Page 20: Compression Commands in Linux

bzip2 decompression

filename.bz2

->

filename

filename.bz filename

filename.tbz2 filename.tar

filename.tbz filename.tar

anyothername anyothername.out

• If the file does not end in one of the recognised endings: • bz2• bz• tbz2 • Tbz

• bzip2 uses the original name with.out appended.

Page 21: Compression Commands in Linux

Linux / Unix Command: tar

Page 22: Compression Commands in Linux

tar

• tar is a general-purpose archiving utility – Stands for Tape Archive – capable of packing many files into a single

archive file,– while retaining information needed to restore

the files fully, such as file permissions and ownership.

Page 23: Compression Commands in Linux

Tar options

• -c– Create a new archive

• -x– Extract files from an archive

• -t– List table of contents to an archive

• -r– append

Page 24: Compression Commands in Linux

Tar options• -u

– Update files • -d

– Compare files in the archive to those in the file system

• -v– print verbose information

• -k– To keep any existing files when extracting

• f filename– To specify that the tar file to be read or written is filename.

Page 25: Compression Commands in Linux

• Parameter for gzip and bzip2:Parameter for gzip and bzip2:• z

– To specify that the data to be written to the tar file should be compressed or that the data in the tar file is compressed with gzip.

• j– Like z, but uses bzip2 instead of gzip;

• works only with newer versions of tar.

• Note:

– f must be the last letter in the list of options.

Tar options

Page 26: Compression Commands in Linux

tar

• tar saves the pathname of each file relative to the location where the tar file was originally created.– tar cvf bin.tar /bin the directory bin is created in the working

directory of tar– You can override this behavior using the P option when packing

tar files (not recommended to do!)

Page 27: Compression Commands in Linux

Other commands

Page 28: Compression Commands in Linux

Compress

Synopsis:•compress [ -f ] [ -v ] [ -c ] [ -V ] [ -r ] [ -b bits ] [ name ... ]•uncompress [ -f ] [ -v ] [ -c ] [ -V ] [ name ... ] •zcat [ -V ] [ name ... ]

Page 29: Compression Commands in Linux

zip

SYNOPSIS•zip [-aABcdDeEfFghjklLmoqrRSTuvVwXyz!@$] [-b path] [-n suffixes] [-t mmddyyyy] [-tt mmddyyyy] [ zipfile [ file1 file2 ...]] [-xi list]•zipcloak [-dhL] [-b path] zipfile•zipnote [-hwL] [-b path] zipfile•zipsplit [-hiLpst] [-n size] [-b path] zipfile

Page 30: Compression Commands in Linux

unzip

SYNOPSIS

•unzip [-Z] [-cflptuvz[abjnoqsCLMVX$/:]] file[.zip] [file(s) ...] [-x xfile(s) ...] [-d exdir]

•unzip will list, test, or extract files from a ZIP archive.

Page 31: Compression Commands in Linux

The End! ;)The End! ;)