Thursday, August 18, 2011

Tar Files... Basic Tar Commands

Tar Files:

  1. Used to collect many files into a one larger file for distribution or archiving.
  2. It preserves file system information like user and group permissions, dates and directory structure.
  3. A ".tar" file is not a compressed files, it is a collection of files within a single file uncompressed. If the file is a .tar.gz ("tarball") or ".tgz" file it is a collection of files that is compressed.
  4. A compressed tar file is called a tarball.
 
Creating a tar file:
tar -cvwf file.tar myfile.txt
tar -cvwf myhome.tar home/

Extracting the files from a tar file:
tar -xvwf myfile.tar
tar -xvwzf myfile.tar.gz

I hope the above examples are self explanatory.. For various switches etc see Tar man pages.. Few important switches are:

  • c tells tar to create a new tar file
  • f tells tar to name it file.tar or myhome.tar as in above example
  • v verbose output, show, e.g., during create or extract, the files being stored into or restored from the tar file.
  • z use zip/gzip to compress the tar file or to read from a compressed tar file.
 

No comments:

Post a Comment