File Analysing Commands In Unix

Contents 
1 gzip 
2 gunzip 
3 zcat 
4 gzcat 
5 tar 
6 pax 
7 bzip2 
8 zip 
9 compress 

1) gzip
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 like gunzip.
-1  Performance: Use fast compression (somewhat bigger result)
-9  Performance: Use best compression (somewhat slower)
Examples:

Compress the file named README. Creates README.gz and deletes README.

$ gzip README
Compress the file called README. The standard output (which is the compressed file) is redirected by the shell to gzips/README.gz. Keeps README.

$ gzip -c README > gzips/README.gz
Use gzip without arguments to compress README.

$ < README gzip > gzips/README.gz
 

2) gunzip
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 of gzip README.gz by replacing the compressed version of the file with the original, uncompressed version. Creates README and deletes README.gz.

$ gunzip README.gz
Write the uncompressed contents of README.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 files package.tgz as short for package.tar.gz.
 

3) zcat
zcat is same thing as uncompress -c, though on many systems it is actually same as "gzcat" and gunzip -c.
 

4) gzcat
gzcat is same as gunzip -c which is gzip -dc.
 

5) tar
tar archives without compression.

An archive contains one or more files or directories. (If archiving multiple files, it might be better to put them in one directory, so extracting will put the files into their own directory.)

Options to tar are confusing. Specify a mode every time.

Modes:

-c  create an archive (files to archive, archive from files)
-x  extract an archive (archive to files, files from archive)
Options:

-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

Examples:

Compress (gzip) and package (tar) the directory myfiles to create myfiles.tar.gz:

$ tar -czvf myfiles.tar.gz myfiles
Uncompress (gzip) and unpack compressed package, extracting contents from myfiles:

$ 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 the myfiles 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 and to-stuff

$ ls -F
from-stuff/
to-stuff/
As described in Running Linux, one can mirror everything from from-stuff to to-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.
 

6) pax
pax is like "tar" but with different command-line syntax. Because "pax" does not assume the tape device, some prefer it to "tar".

$_ The File Compression module or this section of Wikibooks Guide to Unix Computing is a stub.
You can help Wikibooks by expanding it.
 

7) bzip2
bzip2 and bunzip2 are similar to "gzip"/"gunzip" but with a different compression method. Compression is generally better but slower than "gzip". Decompression is somewhat fast.

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

$_ The File Compression module or this section of Wikibooks Guide to Unix Computing is a stub.
You can help Wikibooks by expanding it.
 

8) zip
zip is an archive which compresses the members individually. (Imagine gzip of every file before tar-ing them, but with a different format.) The "zip" format is a common archiving file format used on Microsoft Windows PCs.

$_ The File Compression module or this section of Wikibooks Guide to Unix Computing is a stub.
You can help Wikibooks by expanding it.
 

9) compress
compress is a compressed file format that is popular on UNIX systems. Files compressed with compress will have a ".Z" extension appended to its name.

Unix

See Also
The File Compression Commands

Have a Unix Problem
Do you have a UNIX Question?

Unix Books :-
UNIX Programming, Certification, System Administration, Performance Tuning Reference Books

Return to : - Unix System Administration Hints and Tips

(c) www.gotothings.com All material on this site is Copyright.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
All product names are trademarks of their respective companies.
The site www.gotothings.com is in no way affiliated with or endorsed by any company listed at this site.
Any unauthorised copying or mirroring is prohibited.