tar 打包压缩
[root@linux ~]# tar [-cxtzjvfpPN] 文件或目录
常用参数:
-c :生成tar文件
-x :解压缩tar文件
-t :查看 tarfile 文件(tarfile:打包但未压缩的tar文件)
-z :使用 gzip 压缩
-j :使用 bzip2 压缩
-v :显示命令执行过程
-f :指定文件名,-f 后要立即接文件名
-p :保留原始文件权限
-P :使用绝对路径压缩
-N :只压缩比指定日期新的文件
--exclude FILE:打包压缩时,排除指定文件
[root@linux ~]# tar -cvf /tmp/etc.tar /etc
#打包但不压缩/etc目录下的所有文件,指定打包文件名为etc.tar并放在/tmp目录下
[root@linux ~]# tar -zcvf /tmp/etc.tar.gz /etc
#打包并用gzip压缩
[root@linux ~]# tar -jcvf /tmp/etc.tar.bz2 /etc
#打包并用bzip2压缩
[root@linux ~]# tar -ztvf /tmp/etc.tar.gz
#查看打包文件,如果是gzip压缩的必须加-z选项
[root@linux ~]# cd /usr/local/src
[root@linux src]# tar -zxvf /tmp/etc.tar.gz
#将 /tmp/etc.tar.gz 解压到 /usr/local/src 目录下
[root@linux ~]# cd /tmp
[root@linux tmp]# tar -zxvf /tmp/etc.tar.gz etc/passwd
#在 /tmp 目录下,只将 /tmp/etc.tar.gz 文件内的 etc/passwd 解压缩,没有 "/"
[root@linux ~]# tar -zcvpf /tmp/etc.tar.gz /etc
#压缩/etc目录下的所有文件并保留原始属性
[root@linux ~]# tar -N '2005/06/01' -zcvf home.tar.gz /home
#只压缩比2005/06/01日期新的文件
[root@linux ~]# tar --exclude /home/dmtsai -zcvf myfile.tar.gz /home/* /etc
#压缩 /home, /etc ,但排除 /home/dmtsai
[root@linux ~]# cd /tmp
[root@linux tmp]# tar -cvf - /etc | tar -xvf -
#将 /etc/ 压缩后直接解压到 /tmp 目录下,不产生中间文件。输出文件变成 - 而输入文件也变成 - #其实就是复制的过程。