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/*