Thursday, June 23, 2011

In linux, what is tar

 In linux; tar  (Tape ARchive) is file format and name of a program used to simply combine a few files into a single file, for easy storage and distribution. (.zip and .rar in window)
              In computing tar (derived from tape archive) is both a file format and the name of a program used to handle such files.
  • *.tar
  • *.tgz is equivalent to *.tar.gz (gzip)
  • *.tbz and *.tb2 are equivalent to* .tar.bz2 (bzip)
  • *.taz is equivalent to *.tar.Z
  • *.tlz is equivalent to *.tar.lz
  • *.txz is equivalent to *.tar.xz
A tar file or compressed tar file is commonly referred to as a tarball
Note: 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. If you are looking to compress a file you would create the tar file then gzip the file.

1. Creating an archive using tar command :
1.1    Creating a tar file:
             $ tar cvf archive_name.tar dirname/
  • The letter c means "create archive".
  • The letter v means "verbose", which tells tar to print all the filenames as they are added to the archive.
  • The letter f tells tar that the name of the archive appears next (right after these options).
1.2    Creating a tarred file that is compressed with gzip
            $ tar cjzf archive_name.tgz dirname/
                 'z' means "compress this archive with gzip

1.3    Creating a tarred file that is compressed with bzip
            $ tar cvjf archive_name.tbz dirname/
                   'j' means "compress this archive with bzip


2. Extracting (untar) an archive using tar command
2.1    Extract a *.tar archieve
            $ tar xvf archieve_name.tar
                   x – extract files from archive

2.2    Extract a gzipped tar archive ( *.tgz )
           $ tar xvzf archieve_name.tgz

2.3    Extracting a bzipped tar archive ( *.tbz ) 

           $ tar xvjf archieve_name.tbz


3. Listing an archive using tar command
3.1   View the tar archive file
$ tar tvf archive_name.tar

 

3.2   Extract a gzipped tar archive ( *.tgz )

          $ tar tvzf archieve_name.tgz

3.3   Extracting a bzipped tar archive ( *.tbz )

          $ tar tvjf archieve_name.tbz