tar (选项) (参数)bash
[root@sxooky test]# tar cf script.tar catpv.sh diffbase.sh #仅打包,不压缩! [root@sxooky test]# tar zcf script2.tar.gz catpv.sh diffbase.sh #打包后,以 gzip 压缩 [root@sxooky test]# tar jcf script3.tar.bz2 catpv.sh diffbase.sh #打包后,以 bzip2 压缩 [root@sxooky test]# ll script* -rw-r--r-- 1 root root 1398 Mar 31 15:23 script2.tar.gz -rw-r--r-- 1 root root 1515 Mar 31 15:23 script3.tar.bz2 -rw-r--r-- 1 root root 10240 Mar 31 15:23 script.tar
在选项f以后的文件档名是本身取的,咱们习惯上都用 .tar 来做为辨识。spa
若是加z选项,则以.tar.gz或.tgz来表明gzip压缩过的tar包;code
若是加j选项,则以.tar.bz2来做为tar包名。ip
[root@sxooky test]# tar tf script3.tar.bz2 catpv.sh diffbase.sh
[root@sxooky test]# mkdir test_tar test2_tar [root@sxooky test]# tar xf script2.tar.gz -C test_tar/ #解压所有文件 [root@sxooky test]# tar xf script2.tar.gz -C test2_tar/ catpv.sh #解压指定文件 [root@sxooky test]# ll test* test2_tar: total 4 -rw-r--r-- 1 root root 874 Mar 24 17:35 catpv.sh test_tar: total 8 -rw-r--r-- 1 root root 874 Mar 24 17:35 catpv.sh -rw-r--r-- 1 root root 1699 Mar 15 13:50 diffbase.sh [root@sxooky test]# tar tf script3.tar.bz2 catpv.sh diffbase.sh
tar -N "2012/11/13" -zcvf log17.tar.gz test
tar --exclude scf/service -zcvf scf.tar.gz scf/*