内容概要:
1. gzip工具
2. bzip2压缩工具
3. xz
4. zip及unzip
5. tar打包工具
语法:tar [-zjxcvfpP] filename
辨析:首先要弄清两个概念:打包和压缩。打包是指将一大堆文件或目录变成一个总的文件;压缩则是将一个大的文件通过一些压缩算法变成一个小文件。
在参数 f 之后的文件档名是自己取的,我们习惯上都用 .tar 来作为辨识。 如果加 z 参数,则以 .tar.gz 或 .tgz 来代表 gzip 压缩过的 tar包; 如果加 j 参数,则以 .tar.bz2 来作为tar包名。
-c: 建立压缩档案
-x:解压
-v:显示所有过程
-z:有gzip属性
-j:有bz2属性
-J :有xz属性
-f: 使用档案名字,切记,这个参数是最后一个参数,后面只能接档案名
打包 [[email protected] mayang]# tar -cvf 12.tar 1.txt 2.txt
1.txt
2.txt
打包+压缩[[email protected] mayang]# tar -zcvf 13.tar.gz 1.txt 3.txt
1.txt
3.txt
解压[[email protected] sundong]# tar -zxvf 13.tar.gz
1.txt
3.txt
扩展学习知识:
1. 用tar远程拷贝数据 http://www.aminglinux.com/bbs/thread-152-1-1.html
[[email protected] mayang]# tar cvf - 5.txt | ssh 113.57.219.54 "cd /copy1/; tar xvf -"
5.txt
[email protected]‘s password:
Permission denied, please try again.
[email protected]‘s password:
5.txt
[[email protected] mayang]# ll
total 28
-rw-r--r--. 1 root root 138 Jun 29 05:57 1.txt
-rw-r--r--. 1 root root 21 Jun 29 06:09 2.txt
-rw-------. 1 root root 476 Jun 29 06:17 3.txt
-rwxr-xr-x. 1 root root 10688 Jun 30 06:33 5.txt
drwxr-xr-x. 2 root root 4096 Jun 30 06:54 test
[[email protected] mayang]#