TAR 命令
Creating an archive using tar command(创建压缩文件)
Create linux tar gz (Gzip) archive :
tar -czvf myarchive.tgz mydirectory/
tar -czvf myarchive.tar.gz 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 tar archive (withouth compresion)
tar -cvf myarchive.tar mydirectory/
Create linux tar.bz2 archive
tar -cvfj myarchive.tar.bz2 mydirectory/
tar -cvfj myarchive.tb2 mydirectory/
tar -cvfj myarchive.tbz mydirectory/
Note:To create highly compressed tar file we use option as j(filter the archive through bzip2).
Note: tar.bz2 and tbz is similar as tb2
Extracting linux tar archive(解压文件):
Extract linux tar gz (Gzip) archive
tar -xvzf 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 -xvjf mystuff.tar.bx2
Extract linux tar archive to speciefied directory(文件到目标目录下)
tar -xvzf filename.tar.gz -C /desired/path
-C directory file
Reference media:
[1]http://linuxbasiccommands.wordpress.com/2008/04/04/linux-tar-command/
[2]http://www.tecmint.com/18-tar-command-examples-in-linux/