ºìÁªLinuxÃÅ»§
Linux°ïÖú

tarÃüÁîµÄʹÓ÷½·¨

·¢²¼Ê±¼ä:2010-10-30 12:49:36À´Ô´:ºìÁª×÷Õß:YUZHIBOYI
tarÃüÁî
[root@linux ~]# tar [-cxtzjvfpPN] ÎļþÓëĿ¼....
²ÎÊý£º
-c£º½¨Á¢Ò»¸öѹËõÎļþµÄ²ÎÊýÖ¸Áî(createµÄÒâ˼)£»
-x£º½â¿ªÒ»¸öѹËõÎļþµÄ²ÎÊýÖ¸Á
-t£º²é¿´tarfileÀïÃæµÄÎļþ£¡
Ìرð×¢Ò⣬ÔÚ²ÎÊýµÄÏ´ïÖУ¬c/x/t½öÄÜ´æÔÚÒ»¸ö£¡²»¿Éͬʱ´æÔÚ£¡
ÒòΪ²»¿ÉÄÜͬʱѹËõÓë½âѹËõ¡£
-z£ºÊÇ·ñͬʱ¾ßÓÐgzipµÄÊôÐÔ£¿Ò༴ÊÇ·ñÐèÒªÓÃgzipѹËõ£¿
-j£ºÊÇ·ñͬʱ¾ßÓÐbzip2µÄÊôÐÔ£¿Ò༴ÊÇ·ñÐèÒªÓÃbzip2ѹËõ£¿
-v£ºÑ¹ËõµÄ¹ý³ÌÖÐÏÔʾÎļþ£¡Õâ¸ö³£Ó㬵«²»½¨ÒéÓÃÔÚ±³¾°Ö´Ðйý³Ì£¡
-f£ºÊ¹ÓõµÃû£¬ÇëÁôÒ⣬ÔÚfÖ®ºóÒªÁ¢¼´½ÓµµÃûร¡²»ÒªÔÙ¼Ó²ÎÊý£¡
¡¡¡¡¡¡ÀýÈçʹÓáºtar -zcvfP tfile sfile¡»¾ÍÊÇ´íÎóµÄд·¨£¬ÒªÐ´³É
¡¡¡¡¡¡¡ºtar -zcvPf tfile sfile¡»²Å¶Ôร¡
-p£ºÊ¹ÓÃÔ­ÎļþµÄÔ­À´ÊôÐÔ£¨ÊôÐÔ²»»áÒÀ¾ÝʹÓÃÕ߶ø±ä£©
-P£º¿ÉÒÔʹÓþø¶Ô·¾¶À´Ñ¹Ëõ£¡
-N£º±ÈºóÃæ½ÓµÄÈÕÆÚ(yyyy/mm/dd)»¹ÒªÐµIJŻᱻ´ò°ü½øн¨µÄÎļþÖУ¡
--exclude FILE£ºÔÚѹËõµÄ¹ý³ÌÖУ¬²»Òª½«FILE´ò°ü£¡
·¶Àý£º
·¶ÀýÒ»£º½«Õû¸ö/etcĿ¼ÏµÄÎļþÈ«²¿´ò°ü³ÉΪ/tmp/etc.tar
[root@linux ~]# tar -cvf /tmp/etc.tar /etc <==½ö´ò°ü£¬²»Ñ¹Ëõ£¡
[root@linux ~]# tar -zcvf /tmp/etc.tar.gz /etc <==´ò°üºó£¬ÒÔgzipѹËõ
[root@linux ~]# tar -jcvf /tmp/etc.tar.bz2 /etc <==´ò°üºó£¬ÒÔbzip2ѹËõ
#Ìرð×¢Ò⣬ÔÚ²ÎÊýfÖ®ºóµÄÎļþµµÃûÊÇ×Ô¼ºÈ¡µÄ£¬ÎÒÃÇÏ°¹ßÉ϶¼ÓÃ.tarÀ´×÷Ϊ±æʶ¡£
#Èç¹û¼Óz²ÎÊý£¬ÔòÒÔ.tar.gz»ò.tgzÀ´´ú±ígzipѹËõ¹ýµÄtar file¡«
#Èç¹û¼Ój²ÎÊý£¬ÔòÒÔ.tar.bz2À´×÷Ϊ¸½µµÃû°¡¡«
#ÉÏÊöÖ¸ÁîÔÚÖ´ÐеÄʱºò£¬»áÏÔʾһ¸ö¾¯¸æѶϢ£º
#¡ºtar: Removing leading `/' from member names¡»ÄÇÊǹØ춾ø¶Ô·¾¶µÄÌØÊâÉ趨¡£
·¶Àý¶þ£º²éÔÄÉÏÊö/tmp/etc.tar.gzÎļþÄÚÓÐÄÄЩÎļþ£¿
[root@linux ~]# tar -ztvf /tmp/etc.tar.gz
#ÓÉì¶ÎÒÃÇʹÓÃgzipѹËõ£¬ËùÒÔÒª²éÔĸÃtar fileÄÚµÄÎļþʱ£¬
#¾ÍµÃÒª¼ÓÉÏzÕâ¸ö²ÎÊýÁË£¡ÕâºÜÖØÒªµÄ£¡
·¶ÀýÈý£º½«/tmp/etc.tar.gzÎļþ½âѹËõÔÚ/usr/local/srcµ×ÏÂ
[root@linux ~]# cd /usr/local/src
[root@linux src]# tar -zxvf /tmp/etc.tar.gz
#ÔÚÔ¤ÉèµÄÇé¿öÏ£¬ÎÒÃÇ¿ÉÒÔ½«Ñ¹ËõµµÔÚÈκεط½½â¿ªµÄ£¡ÒÔÕâ¸ö·¶ÀýÀ´Ëµ£¬
#ÎÒÏȽ«¹¤×÷Ŀ¼±ä»»µ½/usr/local/srcµ×Ï£¬²¢Çҽ⿪/tmp/etc.tar.gz£¬
#Ôò½â¿ªµÄĿ¼»áÔÚ/usr/local/src/etcÄØ£¡ÁíÍ⣬Èç¹ûÄú½øÈë/usr/local/src/etc
#Ôò»á·¢ÏÖ£¬¸ÃĿ¼ÏµÄÎļþÊôÐÔÓë/etc/¿ÉÄÜ»áÓÐËù²»Í¬à¸£¡
·¶ÀýËÄ£ºÔÚ/tmpµ×Ï£¬ÎÒÖ»ÏëÒª½«/tmp/etc.tar.gzÄÚµÄetc/passwd½â¿ª¶øÒÑ
[root@linux ~]# cd /tmp
[root@linux tmp]# tar -zxvf /tmp/etc.tar.gz etc/passwd
#ÎÒ¿ÉÒÔ͸¹ýtar -ztvfÀ´²éÔÄtarfileÄÚµÄÎļþÃû³Æ£¬Èç¹ûµ¥Ö»ÒªÒ»¸öÎļþ£¬
#¾Í¿ÉÒÔ͸¹ýÕâ¸ö·½Ê½À´Ï´עÒâµ½£¡etc.tar.gzÄڵĸùĿ¼/ÊDZ»ÄõôÁË£¡
·¶ÀýÎ壺½«/etc/ÄÚµÄËùÓÐÎļþ±¸·ÝÏÂÀ´£¬²¢ÇÒ±£´æÆäȨÏÞ£¡
[root@linux ~]# tar -zxvpf /tmp/etc.tar.gz /etc
#Õâ¸ö-pµÄÊôÐÔÊǺÜÖØÒªµÄ£¬ÓÈÆäÊǵ±ÄúÒª±£ÁôÔ­±¾ÎļþµÄÊôÐÔʱ£¡
############################################################
·¶ÀýÁù£ºÔÚ/homeµ±ÖУ¬±È2005/06/01еÄÎļþ²Å±¸·Ý
[root@linux ~]# tar -N '2005/06/01' -zcvf home.tar.gz /home
·¶ÀýÆߣºÎÒÒª±¸·Ý/home, /etc£¬µ«²»Òª/home/dmtsai
[root@linux ~]# tar --exclude /home/dmtsai -zcvf myfile.tar.gz /home/* /etc
·¶Àý°Ë£º½«/etc/´ò°üºóÖ±½Ó½â¿ªÔÚ/tmpµ×Ï£¬¶ø²»²úÉúÎļþ£¡
[root@linux ~]# cd /tmp
[root@linux tmp]# tar -cvf - /etc | tar -xvf -
#Õâ¸ö¶¯×÷ÓеãÏñÊÇcp -r /etc /tmpÀ²¡«ÒÀ¾ÉÊÇÓÐÆäÓÐÓÃ;µÄ£¡
#ҪעÒâµÄµØ·½ÔÚì¶Êä³öµµ±ä³É-¶øÊäÈëµµÒ²±ä³É-£¬ÓÖÓÐÒ»¸ö|´æÔÚ¡«
#Õâ·Ö±ð´ú±ístandard output, standard inputÓë¹ÜÏßÃüÁîÀ²£¡

ps:²é¿´ tar.gz ÀïµÄÎļþÁбí
gzip -d -c *.tar.gz | tar tvf -
(ÔðÈα༭£ºadmin)
ÎÄÕÂÆÀÂÛ

¹²ÓÐ 6 ÌõÆÀÂÛ

  1. qq9293000079 ÓÚ 2011-07-20 12:29:23·¢±í:

    À´¿´¿´£¬Ëæ±ãѧϰÏÂ

  2. ÌìÕ滨Óï ÓÚ 2011-07-14 15:43:09·¢±í:

    ÎÒÖ»¼Çס.tar.gz tar.bz2µÄ¾Í¿ÉÒÔÁË¡£¡£ºÇºÇ¡¢

  3. rhel5 ÓÚ 2011-03-24 19:53:18·¢±í:

    ѧϰÁË

  4. fujiefujie ÓÚ 2011-02-23 16:44:12·¢±í:

    --remove-files

  5. yeziliang ÓÚ 2010-11-26 22:08:03·¢±í:

    ÓÐûÓÐÆäËüÃüÁ£¡

  6. drivers ÓÚ 2010-10-30 16:58:31·¢±í:

    ˳·¿´¿´