Friday, March 9, 2012

gzip,tar,zcat

TAR :
tar only makes a single file out of multiple files, it doesn't do compression unless combined a compression program such as gzip or bzip2 (which you can call from within tar by using the -zor -j options, respectively). zip combines both the archiving and compression in one program.

Tar :
Make a backup of your files. Unix is unforgiving and will delete anything if you make a mistake. There's no Recycle Bin either.
Create a tar file with these fancy commands:
tar czf packageName.tgz file1 file2 *.html paris_hilton_*.jpg ...
where packageName.tgz is the name of the final tar file that will hold all your files.
NOTE: If you forget to include the name of the tar file (ie. packageName.tgz) you will destroy the first file you list on the tar command line. Fucking genius, Unix.
Make sure everything was tarred Make a new directory and copy the tar file into it.
You can untar the file with: tar xvzf packageName.tgz

GZIP

1. Gzip is a compression tool used to reduce the size of a file 2. Tar is an archiver used to to combine multiple files into one 3. Gzip and Tar are usually used in tandem to create Tarballs that are compressed significantly 4. Extracting an individual file can take a lot longer with zipped tarballs than with other formats
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

[edit]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.
[edit]zcat
zcat is same thing as uncompress -c, though on many systems it is actually same as "gzcat" and gunzip -c.
[edit]gzcat
gzcat is same as gunzip -c which is gzip -dc.
[edit]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.)
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 -)

ONE INTERRESTING EXAMPLE : zcat file.z | wc -l



Source : wikipedia :No copyright violation intended !! Just sharing knowledge and giving credits to the source !

No comments:

Post a Comment