Linux/Unix File Compression Tools

Compression tools.
Most should work on Solaris 9,10,11, and Linux flavours.

# -c = write compressed file to stdout. Do not delete original file
# -d = Act like gunzip
# -1 = Performance: Use fast compression (somewhat bigger result)
# -9 = Performance: Use best compression (somewhat slower)
# compress the file named README and delete README
# compress and keep the file called README
gzip -c README > gzips/README.gz
# use gzip without arguments to compress README
< README gzip > gzips/README.gz
# uncompress .tgz file
gzip -dc filename.tgz | tar xf –

-c Write uncompressed data to stdout. Do not delete original file.
gunzip README.gz
gunzip -c README.gz | more
gunzip < README.gz | more

uncompress -c:

gunzip -c:
gzip -dc
tar – archive without compression

-c = create an archive (files to archive, archive from files)
-x = extract an archive (archive to files, files from archive)
-f  = FILE name of archive – must specify unless using tape drive for archive
-v = be verbose, list all files being archived/extracted
-z = create/extract archive with gzip/gunzip
-j  = create/extract archive with bzip2/bunzip2
# compress (gzip) and package (tar) the directory myfiles to create myfiles.tar.gz:
tar -czvf myfiles.tar.gz myfiles
# tar of the fly all in current directory and extract it somewhere else.
tar cf – . | (cd _destination_dir_; tar xvf -)
# uncompress (gzip) and unpack compressed package, extracting contents from myfiles:
tar -xzvf myfiles.tar.gz
cpio – archive without compression

When creating an archive, a list of files is fed to its standard-input .
– cpio -o – Copy-Out mode: Files are copied out from the filesystem to create an archive.
– cpio -i – Copy-In mode: Files from an existing archive are restored/extracted.
– cpio -p – Pass-Through mode: cpio is used to copy files from one location in the directory-tree to another.
In addition comes:
– cpio -t – List archive: The content of an archive is listed without extracting it.
– cpio -tv – Here the verbose-option (-v) will cause a “long listing”, with permissions, size and ownership.
-d cpio creates  destination directory  to make it.
# archive all docs in current directory
ls *.doc | cpio -ov > word-docs.cpio
# using find to create an archive with all txt-files in and below the current directory:
find . -name “*.txt” | cpio -ov > text-files.cpio
# using find and fgrep to create an archive of just the txt-files containing the word wiki (any case):
find . -name “*.txt” -exec fgrep -l -i “wiki” {} \; | cpio -ov > wiki.cpio
# using several list of files, but first after sort-ing and uniq-ing them:
cat files1 files2 files3 | sort | uniq | cpio -ov > myfiles.cpio
# To add more files, use the append-option (-A).
# Specify the file with the file-option (-F):
cat files4 | cpio -ovA -F myfiles.cpio
# To extract files (being verbose):
$ cpio -iv < myfiles.cpio
# To extract files, while creating directories as needed:
cpio -ivd < myfiles.cpio
To list the content of an archive, short listing:
cpio -t < myfiles.cpio
To list the content of an archive, long listing:
cpio -tv < myfiles.cpio

pax is like “tar” but with different command-line syntax.

bzip2 and bunzip2 are similar to “gzip”/”gunzip” but with a different compression method.
An option of -1 through -9 can be used to specify how good bzip2 should compress.
The number tells how large “chunks” in steps of 100kB should compress at a time, so using bzip2 -5 will compress in chunks of 500kB each.
By default bzip2 uses 900kB chunks for best possible compression.

bzcat is same as bunzip2 -c which is bzip2 -dc.

Like for gzip the quality of the compression can be specified by giving a number between 1 and 9 as an option (e.g. zip -5). 1 is quickest, but gives a low-quality compression. 9 gives the highest quality of compression, but is slow.
Note that a zip-archive contains individualy compressed files collected into a single file.

Compress is a compression file format that is popular on UNIX systems.
Files compressed with compress will have a “.Z” extension appended to its name.

Leave a Reply

Your email address will not be published. Required fields are marked *