首页 > 代码库 > TAR 命令

TAR 命令

Create linux tar gz (Gzip) archive   (创建压缩文件)

tar -czvf myarchive.tgz mydirectory/

We use the -t option to create an linux tar archive

  • c – Creates a new .tar archive file.
  • v – Verbosely(啰嗦地) show the .tar file progress.
  • f – File name type of the archive file.
  • To create a compressed gzip archive file we use the option as z.

Note that .tgz is the same thing as .tar.gz

Create linux simple tar archive (withouth compresion)

tar -cvf myarchive.tar mydirectory/

Create linux tar.bz2 archive

tar -cvfj myarchive.tar.bz2 mydirectory/

Note:To create highly compressed tar file we use option as j.

Extracting linux tar archive:

Extract linux tar gz (Gzip) archive
tar -xzvf mystuff.tgz

To untar or extract a tar file, just issue following command using option x (extract).

Extract linux simple tar archive

tar -xvf mystuff.tar

Exterct linux simple tar.bz2 archive

tar -jxvf mystuff.tar.bx2

Extract linux tar archive to speciefied directory
tar -xvzf filename.tar.gz -C /desired/path

And now let us shortly explain this command

Usage: tar [OPTION]… [FILE]…



Let us check the option used in this example

-c, –create                      create a new archive
-z, –gzip, –ungzip        filter the archive through gzip
-v, –verbose                   verbosely list files processed
-f, –file=ARCHIVE          use archive file or device ARCHIVE

-C directory file
Performs a chdir  operation on directory and performs the c (create) or r (replace) operation on file .
In c and r mode, this changes the directory before adding the following files. In x mode, change directories after opening the archive but before extracting entries from the archive.

Testing / viewing your archive

tar -tvf myarchive.tar
tar -tzvf myarchive.tgz

Here we used the – t opton
-t, –list                           list the contents of an archive

————————————————-

Go ahead, try out these commands and stay tuned; we will come up with more doccumentation on linux tar command

The article source: http://linuxbasiccommands.wordpress.com/2008/04/04/linux-tar-command/