takes
Used to compress and decompress files. tar itself does not have compression, packing only a function of compressing and decompressing is related to call other functions to complete.
Clarify two concepts: packing and compression. Packaging refers to a lot of files or directories into a general file; a large file compression sucked into a small file with some compression algorithms
Common parameters:
-c 建立新的压缩文件 (建立压缩档案) -f 指定压缩文件 -r 添加文件到已经压缩文件包中 (向压缩归档文件末尾追加文件) -u 添加改了和现有的文件到压缩包中 (向压缩归档文件末尾追加文件) -x 解压文件 -t 显示压缩文件中的内容 (查看内容) -z 支持gzip压缩 -j 支持bzip2压缩 -Z 支持compress解压文件 -v 显示操作过程 (显示所有过程)
two:
About gzip and bzip2 compression:
gzip 实例:压缩 gzip fileName .tar.gz 和.tgz 解压:gunzip filename.gz 或 gzip -d filename.gz 对应:tar zcvf filename.tar.gz tar zxvf filename.tar.gz bz2实例:压缩 bzip2 -z filename .tar.bz2 解压:bunzip filename.bz2或bzip -d filename.bz2 对应:tar jcvf filename.tar.gz 解压:tar jxvf filename.tar.bz2
Example:
(1) All files packaged into a tar package
tar -cvf log.tar 1.log,2.log 或tar -cvf log.*
(2) the current directory all packaged into a txt file txt.tar
tar -cvf txt.tar *.txt
(3) the current directory of all packaged into txt file txt.tar, and which was gzip compression, to generate a gzip compressed package named txt.tar.gz
tar -zcvf txt.tar.gz *.txt
(4) packaged into a txt file directory all txt.tar, and compressed with bzip2 which generates a bzip2 compressed package named txt.tar.bz2
tar -jcvf txt.tar.bz2 *.txt
(5) all files and directories under / etc package to the specified directory, and use the gz compression
tar -zcvf /tmp/etc.tar.gz /etc
(6) view the contents of the file you just packaged (plus some z, because it is compressed with gzip)
tar -ztvf /tmp/etc.tar.gz
(7) to compress pack / home, / etc, but do not / home / dmtsai
tar --exclude /home/dmtsai -zcvf myfile.tar.gz /home/* /etc
(8) After all packaged txt files into directory txt.tar, compress and which was compressed to generate a compressed umcompress package named txt.tar.Z
tar -Zcvf txt.tar.Z *.txt
(9) to the current directory packet decompression txt.tar
tar -xvf txt.tar
(10) to extract the packet txt.tar / home directory
tar -xvf txt.tar -C /home
(11) unzip the package to the current directory txt.tar.gz
tar -zxvf txt.tar.gz
(12) to the current directory packet decompression txt.tar.bz2
tar -jxvf txt.tar.bz2
(13) to the current directory packet decompression txt.tar.Z
tar -Zxvf txt.tar.Z