How to Identify Different Types of Compression Methods in UNIX
There are a few different types of compression methods in UNIX. This article will show the basic types and how to work with them, including the commands to use. In all cases, compress the files by following the appropriate compress command shown below with the file name. Uncompress them by typing the appropriate uncompress command followed by the file name.
- Difficulty:
- Moderately Challenging
Instructions
-
-
1
For files with a .gz filename extension, the file was compressed with GNUzip. Use the gunzip command to uncompress, and gzip to compress.
-
2
For files with a .zip extension, the commands are unzip and zip. If you want to use a compression method compatible with Microsoft Windows, Apple Mac and other operating systems, this is the best one to use.
-
3
Older style UNIX compressed files can be identified by the .Z file name extension. Commands to use for this format are compress and uncompress.
-
4
For files with a .bz2 extension, the file was compressed using the bzip2 command. To uncompress a .bz2 file, the command to use is bzip2 -d.
-
5
Files with a .tgz extension are simply tar (tape archive) files compressed with gzip. First use gunzip to uncompress, then tar xvf to unpack the archive.
-
6
Files with a .tbz2 extension are simply tar files compressed with bzip2. First use bzip2 -d to uncompress, then tar xvf to unpack the archive.
-
1
Tips & Warnings
Compression saves greatly on disk space. Large files and archives should be compressed for efficient storage if they won't be used very frequently.
Sometimes the unzip utility you pick will not work due to an incorrect file name extension. Try copying the compressed file to a more standard file name extension, then attempt to uncompress.
Not all UNIX systems have every file compression utility installed. If this is the case, attempt to uncompress on a different system, or get the compression utilities you need from the UNIX vendor.
Some unsafe UNIX tar commands will unpack the tar in an absolute location, relative to root, which can be disastrous. Your entire operating system can be overwritten. Before unpacking a tar file, test the location it will unpack to by first issuing the command tar tvf
and observing where the files will be created.