General:Introduction |Explanations |Why Unix-like
Platforms:Linux |BSD
Quick Reference:Commands |Environment Variables |Files |License
gzip compresses files. Each single file is compressed into a single file. The compressed file consists of a GNU zip header and deflated data.
If given a file as an argument, gzip compresses the file, adds a ".gz" suffix, and deletes the original file. With no arguments, gzip compresses the standard input and writes the compressed file to standard output.
Some useful options are:
-c Write compressed file to stdout. Do not delete original file.-d Act likegunzip.-1 Performance: Use fast compression (somewhat bigger result)-9 Performance: Use best compression (somewhat slower)
Examples:
Compress the file namedREADME. CreatesREADME.gz and deletesREADME.
$gzip README
Compress the file calledREADME. The standard output (which is the compressed file) is redirected by the shell togzips/README.gz. KeepsREADME.
$gzip -c README > gzips/README.gz
Use gzip without arguments to compressREADME.
$< README gzip > gzips/README.gz
Links:
gunzip uncompresses a file that was compressed with "gzip" or "compress". It tries to handle both the GNU zip format of gzip and the older Unix compress format. It does this by recognizing the extension (".gz" or ".Z" or several others) of a file.
Some useful options are:
-c Write uncompressed data to stdout. Do not delete original file.
Undo the effect ofgzip README.gz by replacing the compressed version of the file with the original, uncompressed version. CreatesREADME and deletesREADME.gz.
$gunzip README.gz
Write the uncompressed contents ofREADME.gz to standard output. Pipe it into a pager for easy reading of a compressed file.
$gunzip -c README.gz | more
Another way to do that is:
$gunzip < README.gz | more
Some people name filespackage.tgz as short forpackage.tar.gz.
Links:
zcat is same thing asuncompress -c, though on many systems it is actually same as "gzcat" andgunzip -c.
Links:
gzcat is same asgunzip -c which isgzip -dc.
Archives without compression. Not covered by modern POSIX, which covers#pax instead; yet,tar continues to be widely used. An archive contains one or more files or directories.
Options to tar are confusing. Specify a mode every time.
Modes:
Options:
Examples:
Compress (gzip) and package (tar) the directorymyfiles to createmyfiles.tar.gz:
$tar -czvf myfiles.tar.gz myfiles
Uncompress (gzip) and unpack compressed package, extracting contents frommyfiles:
$tar -xzvf myfiles.tar.gz
There are two different conventions concerning gzipped tarballs. One often encounters .tar.gz. The other popular choice is .tgz. Slackware packages use the latter convention.
If you have access to a tape device or other backup medium, then you can use it instead of an archive file. If the material to be archived exceeds the capacity of the backup medium, the program will prompt the user to insert a new tape or diskette.
Use the following command to back up themyfiles directory to floppies:
$tar -cvf /dev/fd0 myfiles
Restore that backup with:
$tar -xvf /dev/fd0
You can also specify standard input or output-f - instead of an archive file or device. It is possible to use copy between directories by piping two "tar" commands together. For example, suppose we have two directories,from-stuff andto-stuff
$ls -Ffrom-stuff/to-stuff/
As described inRunning Linux, one can mirror everything fromfrom-stuff toto-stuff this way:
$tar cf - . | (cd ../to-stuff; tar xvf -)
Reference: Welsh, Matt, Matthias Kalle Dalheimer and Lar Kaufman (1999),Running Linux. Third edition, O'Reilly and Associates.
Links:
cpio is used for creating archives. When creating an archive, a list of files is fed to its standard-input (rather than specifying the files on the commandline). This file-list is typically created byls,find orlocate and then piped directly tocpio; but it can also first be filtered/edited with commands like*grep,sed,sort and others. A (pre-edited) list stored as a file can also be used, by usingcat to feed the pipeline or simply by redirecting the shell's standard-input (<).
cpio works in one of three modes:
In addition comes:
Adding the verbose-option (-v) in Copy-In, Copy-Out and Pass-Through mode, will causecpio to list the files as they're extracted/archived/copied.
Usingls to create an archive (verbosely) with all doc-files in the current directory:
$ls *.doc | cpio -ov > word-docs.cpio
Usingfind to create an archive with all txt-files in and below the current directory:
$find . -name "*.txt" | cpio -ov > text-files.cpio
Usingfind andfgrep to create an archive of just the txt-files containing the wordwiki (any case):
$find . -name "*.txt" -exec fgrep -l -i "wiki" {} \; | cpio -ov > wiki.cpio
Forfgrep the option-i means "ignore case", and the option-l cause it to just list the filenames of files matching the pattern.
Using an existing list of files:
$cpio -ov < file-list.txt > archive.cpio
Using several list of files, but first aftersort-ing anduniq-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
cpio doesn't create directories by default, so use the option-d to make it.
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
Links:
Provides archiving services liketar but with different command-line syntax; provides more archive formats than tar. Becausepax does not assume the tape device, some prefer it totar.
Archive formats to be supported at minimum per POSIX are cpio, pax, and ustar. The FreeBSDpax tool does not support thepax archive format; thepax format is supported by AIX and Solaris.
Although covered by POSIX,pax is usually not installed per default in Linux distributions;tar sees continued use instead. Even when installed as an additional package,pax for Linux does not support the POSIX-requiredpax archive format.
Links:
bzip2 andbunzip2 are similar to "gzip"/"gunzip" but with a different compression method. Compression is generally better but slower than "gzip". Decompression is somewhat fast.
An option of-1 through-9 can be used to specify how goodbzip2 should compress. The number tells how large "chunks" in steps of 100kB should compress at a time, so usingbzip2 -5 foo.bar will compress foo.bar in chunks of 500kB each. Generally, larger chunks means better compression (but probably slower). Onlyundamaged "chunks" can be recovered withbzip2recover from a damaged bzip2-file, so if you've compressed 900kB chunks, you'll loose 900kB of your file if one chunk is damaged - but only 100kB if you used 100kB chunks (bzip2 -1). By defaultbzip2 uses 900kB chunks for best possible compression.
bzcat is same asbunzip2 -c which isbzip2 -dc.
Links:
Adds files to a compressed zip archive. You can extract files from a zip archive usingunzip. The zip format is a common archiving file format used on Microsoft Windows PCs. A zip archive has members compressed individually; imagine gzip of every file before tar-ing them, but with a different format.
Like forgzip 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. In addition 0 can be used (i.e.zip -0) to specify that the files should just be "stored" andnot compressed (a compression of 0%), thus making it possible to usezip to make uncompressed archives.
Note that azip-archive containsindividualy compressed files collected into a single file. This is the opposite of how it's done for most other compressedUnix-archives (e.g.tar.gz andtar.bz2), where the files/directories arefirst collected into a single file -- an archive (e.g.cpio ortar), andthen thissingle file is compressed (e.g. usinggzip orbzip2).
Examples:
Links:
Extracts files from zip archives. See alsozip. You can get a Windows version of Info-ZIP unzip fromGnuWin32. FreeBSD appears to be using a custom version of unzip, distinct from Info-ZIP yet largely compatible with it.
Examples:
Links:
compress is a compressed file format that is popular on UNIX systems. Files compressed withcompress will have a ".Z" extension appended to its name.
Links:
Extracts files from an archive created bycompress.
Links:
Extracts files from a variety of compression formats, including 7z (7-zip) and RAR. License: LGPL. A companion utility to show archive file listing islsar.
Links:
A legacy tool and a file format to create self-extracting file archives, not covered by POSIX. The self-extracting archives are shell scripts.
Links: