------------------------------------------------------------------------------- TAR history The tar command (tape-archive) was originally designed to archive a number of files and complete directories to magnetic tape. However due to its ability to archive directories, and its availability on EVERY unix (and almost all non-unix) platform, it has become the standard archive for files on the unix system. The tar program is even available in the GNU source archives, and is commonly known as `gtar' or gnu-tar. This program can be compiled for the DOS commandline which means that it is available for PCs too. Gnu-tar is basically the same as normal UNIX tar but often has a lot more features (typical of the GNU variants). For example it understands how to perform gzip compression from the single command. Due to its origins the default file to which archiving occurs is the tape drive (typically "/dev/rmt8"). To use this command you need to substute your own filename, or `-' to represent stdin/stdout, otherwise it will attempt to use the tape device which is probably not available for use by you. ------------------------------------------------------------------------------- Normal tar files (no compression) archive a directory "dir" to a file "directory.tar" first change directory (cd) to just above the sub-directory then execute tar cvf subdir.tar dir de-archive the above tar file on tar xvf filename.tar look at the files in tar file tar tvf filename.tar ------------------------------------------------------------------------------- Compressed Tar Files The tar files DO NOT perform any compression on the data as more modern day archives now available. As such archives are normally compressed to form compressed tar files ".tar.Z" compress existing tar file execute compress directory.tar create a compressed-tar of a sub-directory cd to just above the sub-directory tar cvf - subdir | compress > subdir.tar.Z de-archive a compressed-tar zcat filename.tar.Z | tar xvf - list the contents of a compressed-tar file zcat filename.tar.Z | tar tvf - ------------------------------------------------------------------------------- Gzip'ed Tar Files Today a new compression method is available called GZIP which is freely available on ALL machines including PCs. It uses the Lempel-Ziv (LZ77) compression which compresses much better than the normal unix compress program. Also the ungzip code will de-compress BOTH compressed and gziped files. The `gzip' source is available in the GNU FTP archive on most major FTP sites around the world, and pre-compiled PC versions should also be available in PC archives. Gzip'ed tar files use the file extension ".tar.gz" or ".tgz". At one point ".tar.z" (with a little `z') was also used as the suffix string but was found to be too confusing with a normal compressed (".Z") tar archive. gzip existing tar file gzip directory.tar create a gzip'ed tar file of a sub-directory cd to just above the sub-directory tar cvf - subdir | gzip > subdir.tar.gz de-archive a compressed or gzip'ed tar archive gzip -dc filename.tar.gz | tar xvf - list the contents of a compressed or gzip'ed tar archive gzip -dc filename.tar.gz | tar tvf - Gziped compression of a tar file can be improved by archiving all the files of the same type together. EG: order the files archived so all GIF files are togther then all the text files, the html files the jpegs, etc.. Example tar cvf - `ls | sort -t. +1` | gzip > ../file.tar.gz NOTE: this archives the files in the current directory. It is NOT recommended, and your should always arcive a subdirectory. ------------------------------------------------------------------------------- Tar Tcsh aliases I have the following CSH aliases in my .cshrc file to help handle the creation of tar files. #=======8<------CUT HERE--------axes/crowbars permitted--------------- # ... # make things easier alias a alias # ... # set the paging command for `man' and `archive listing' setenv PAGER less # ... #----------- Remote Aliases ----------- # These aliases are defined for use by remote commands # or as part of a file manager or vi shell escape #-------- Archive Aliases ---------- a uc 'uncompress' # compressed tar archives a ltar 'zcat <\!:1 | tar tvf - | ${PAGER}' a ftar 'zcat <\!:1 | tar xvfp - \!:2*' a ttar 'tar cvf - \!:1 | compress > \!:1.tar.Z' # uncompress gzip compressed file a gz 'gzip -v \!:1' a ugz 'gzip -dv \!:1' a ltgz 'gzip -dc \!:1 | tar tvf - | ${PAGER}' a ftgz 'gzip -dc \!:1 | tar xvf - \!:2*' a ttgz 'tar cvf - \!:1 | gzip > \!:1.tgz' #=======8<------CUT HERE--------axes/crowbars permitted--------------- Example to archive a sub-directory ttgz subdir To Tar Gziped archive OR subdir to subdir.tgz You can then delete the sub-directory. NOTE: do NOT have any `/'s in the subdir argument. To de-archive ftgz subdir.tgz and the subdir directory will be re-created in the current directory the archive can then be removed or left as a backup. =============================================================================== --------------- Other Archiving Programs ----------------------- ------------------------------------------------------------------------------- All these archives were developed on NON-UNIX machines and will automatically compress whole directories or individual files into/from a archive in one step processing. This is very important in a DOS like environment without the use of pipes under UNIX. I myself use one of these for archiving signature `quotes' such that I can extract a single quote easily and directly from a shell script. ------------------------------------------------------------------------------- Zip Archive Zip and and alternative version PkZip is the `standard' PC archiving programs. UNIX versions are available on kurango and gucis. They use numerous compression algorithims selected for the best performance for each individual file. Zip a sub-directory zip -r subdir.zip subdir You can also auto remove that subdirectory by adding a -m option. Advantages.. * You can extract a single file from the archive without the program processing the whole archive to do so, as you need to for tar (or gzip'ed tar) archives Disadvantages * Zip is the same compressor as Gzip but, compresses individual files. A Gzip'ed tar archive is compressed over all the files, making Gziped tar files smaller, and for a archive of GIF files this can be 10 times smaller than the same ZIP archive. See /~anthony/info/misc/tgz_vs_zip on this server for more info on this. ------------------------------------------------------------------------------- Bzip2 Compression The newest compression algorithm in common use is bzip2 (suffix .bz2). this is very much like gzip (above) but compresses even better than gzip. It is however slower (EG: time-space tradoff) Again this is only a compression program and NOT an archiver so tar files will be most commonly bzip2'ed. File suffixes are usally ".tar.bz" or ".tar.bz2". The command works just like gzip, so just use the gzip methods above replacing "gzip" with "bzip2". ------------------------------------------------------------------------------- LHarc and Zoo Archives These commands were developed at the time of the ol' Amiga Micro Computers. However a version of the command is available (if you can find it) for UNIX machines. It has the same advantages and disadvangtages as the zip archive above. However it has a much larger set of options and controls than most zip commands. For example unlike zip and tar archives you can do things like... * Pipe out a single file in the archive direct to standard out (EG: pipe out not de-archive!) * extract with OR without the archive directory structure * delete/replace particular archived files, repacking archive afterwards Individual file selection is something very few archiving programs are capable of. I myself use this feature for my random quote message generator so I can output a single file to stdout which is randomly selected from the archives listing. It also make it easy to add, delete and update the individual quotes in the archive without needing to de-archive everything every time (as you need to do with a gzip'ed tar archive). -------------------------------------------------------------------------------