{"id":6722,"date":"2020-03-18T14:16:32","date_gmt":"2020-03-18T06:16:32","guid":{"rendered":"https:\/\/www.linuxcool.com\/?p=6722"},"modified":"2022-05-03T19:09:59","modified_gmt":"2022-05-03T11:09:59","slug":"tar","status":"publish","type":"post","link":"https:\/\/www.linuxcool.com\/tar","title":{"rendered":"tar\u547d\u4ee4 – \u538b\u7f29\u548c\u89e3\u538b\u7f29\u6587\u4ef6"},"content":{"rendered":"\n

tar\u547d\u4ee4\u7684\u529f\u80fd\u662f\u7528\u4e8e\u538b\u7f29\u548c\u89e3\u538b\u7f29\u6587\u4ef6\uff0c\u80fd\u591f\u5236\u4f5c\u51faLinux\u7cfb\u7edf\u4e2d\u5e38\u89c1\u7684.tar\u3001.tar.gz\u3001.tar.bz2\u7b49\u683c\u5f0f\u7684\u538b\u7f29\u5305\u6587\u4ef6\u3002\u5bf9\u4e8eRHEL7\u3001CentOS7\u7248\u672c\u4ee5\u540e\u7684\u7cfb\u7edf\uff0c\u89e3\u538b\u65f6\u53ef\u4ee5\u4e0d\u52a0\u538b\u7f29\u683c\u5f0f\u53c2\u6570\uff08\u5982z\u6216j\uff09\uff0c\u7cfb\u7edf\u80fd\u81ea\u52a8\u8fdb\u884c\u5206\u6790\u5e76\u89e3\u538b\u3002<\/p>\n\n\n\n

\u628a\u8981\u4f20\u8f93\u7684\u6587\u4ef6\u5148\u8fdb\u884c\u538b\u7f29\u518d\u8fdb\u884c\u4f20\u8f93\uff0c\u80fd\u591f\u5f88\u597d\u7684\u63d0\u9ad8\u5de5\u4f5c\u6548\u7387\uff0c\u65b9\u4fbf\u5206\u4eab\u3002<\/p>\n\n\n\n

\u8bed\u6cd5\u683c\u5f0f\uff1a<\/strong>tar \u53c2\u6570 \u6587\u4ef6\u6216\u76ee\u5f55<\/p>\n\n\n\n

\u5e38\u7528\u53c2\u6570\uff1a<\/strong><\/p>\n\n\n\n

-A<\/td>\u65b0\u589e\u6587\u4ef6\u5230\u4ee5\u5b58\u5728\u7684\u5907\u4efd\u6587\u4ef6<\/td><\/tr>
-B<\/td>\u8bbe\u7f6e\u533a\u5757\u5927\u5c0f<\/td><\/tr>
-c<\/td>\u5efa\u7acb\u65b0\u7684\u5907\u4efd\u6587\u4ef6<\/td><\/tr>
-C <\u76ee\u5f55><\/td>\u4ec5\u538b\u7f29\u6307\u5b9a\u76ee\u5f55\u91cc\u7684\u5185\u5bb9\u6216\u89e3\u538b\u7f29\u5230\u6307\u5b9a\u76ee\u5f55<\/td><\/tr>
-d<\/td>\u8bb0\u5f55\u6587\u4ef6\u7684\u5dee\u522b<\/td><\/tr>
-x<\/td>\u4ece\u5f52\u6863\u6587\u4ef6\u4e2d\u63d0\u53d6\u6587\u4ef6<\/td><\/tr>
-t<\/td>\u5217\u51fa\u5907\u4efd\u6587\u4ef6\u7684\u5185\u5bb9<\/td><\/tr>
-z<\/td>\u901a\u8fc7gzip\u6307\u4ee4\u538b\u7f29\/\u89e3\u538b\u7f29\u6587\u4ef6\uff0c\u6587\u4ef6\u540d\u6700\u597d\u4e3a*.tar.gz<\/td><\/tr>
-Z<\/td>\u901a\u8fc7compress\u6307\u4ee4\u5904\u7406\u5907\u4efd\u6587\u4ef6<\/td><\/tr>
-f<\u5907\u4efd\u6587\u4ef6><\/td>\u6307\u5b9a\u5907\u4efd\u6587\u4ef6<\/td><\/tr>
-v<\/td>\u663e\u793a\u6307\u4ee4\u6267\u884c\u8fc7\u7a0b<\/td><\/tr>
-r<\/td>\u6dfb\u52a0\u6587\u4ef6\u5230\u5df2\u7ecf\u538b\u7f29\u7684\u6587\u4ef6<\/td><\/tr>
-u<\/td>\u6dfb\u52a0\u6539\u53d8\u4e86\u548c\u73b0\u6709\u7684\u6587\u4ef6\u5230\u5df2\u7ecf\u5b58\u5728\u7684\u538b\u7f29\u6587\u4ef6<\/td><\/tr>
-j<\/td>\u901a\u8fc7bzip2\u6307\u4ee4\u538b\u7f29\/\u89e3\u538b\u7f29\u6587\u4ef6\uff0c\u6587\u4ef6\u540d\u6700\u597d\u4e3a*.tar.bz2<\/td><\/tr>
-v<\/td>\u663e\u793a\u64cd\u4f5c\u8fc7\u7a0b<\/td><\/tr>
-l<\/td>\u6587\u4ef6\u7cfb\u7edf\u8fb9\u754c\u8bbe\u7f6e<\/td><\/tr>
-k<\/td>\u4fdd\u7559\u539f\u6709\u6587\u4ef6\u4e0d\u8986\u76d6<\/td><\/tr>
-m<\/td>\u4fdd\u7559\u6587\u4ef6\u4e0d\u88ab\u8986\u76d6 <\/td><\/tr>
-w<\/td>\u786e\u8ba4\u538b\u7f29\u6587\u4ef6\u7684\u6b63\u786e\u6027<\/td><\/tr>
-p<\/td>\u4fdd\u7559\u539f\u6765\u7684\u6587\u4ef6\u6743\u9650\u4e0e\u5c5e\u6027<\/td><\/tr>
-P<\/td>\u4f7f\u7528\u6587\u4ef6\u540d\u7684\u7edd\u5bf9\u8def\u5f84\uff0c\u4e0d\u79fb\u9664\u6587\u4ef6\u540d\u79f0\u524d\u7684\u201c\/\u201d\u53f7<\/td><\/tr>
-N <\u65e5\u671f\u683c\u5f0f><\/td>\u53ea\u5c06\u8f83\u6307\u5b9a\u65e5\u671f\u66f4\u65b0\u7684\u6587\u4ef6\u4fdd\u5b58\u5230\u5907\u4efd\u6587\u4ef6\u91cc<\/td><\/tr>
-- -exclude=<\u8303\u672c\u6837\u5f0f><\/td>\u6392\u9664\u7b26\u5408\u8303\u672c\u6837\u5f0f\u7684\u6587\u4ef6<\/td><\/tr>
-- -remove-files<\/td>\u5f52\u6863\/\u538b\u7f29\u4e4b\u540e\u5220\u9664\u6e90\u6587\u4ef6<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n

\u53c2\u8003\u5b9e\u4f8b<\/strong><\/p>\n\n\n\n

\u4f7f\u7528gzip\u538b\u7f29\u683c\u5f0f\u5bf9\u67d0\u4e2a\u76ee\u5f55\u8fdb\u884c\u6253\u5305\u64cd\u4f5c\uff0c\u663e\u793a\u538b\u7f29\u8fc7\u7a0b\uff0c\u538b\u7f29\u5305\u89c4\u8303\u540e\u7f00\u4e3a.tar.gz\uff1a<\/p>\n\n\n\n

[root@linuxcool ~]# tar czvf backup1.tar.gz \/etc<\/strong>\r\ntar: Removing leading `\/' from member names\r\n\/etc\/\r\n\/etc\/mtab\r\n\/etc\/fstab\r\n\/etc\/crypttab\r\n\/etc\/resolv.conf\r\n\/etc\/dnf\/\r\n\u2026\u2026\u2026\u2026\u2026\u2026\u7701\u7565\u90e8\u5206\u8f93\u51fa\u4fe1\u606f\u2026\u2026\u2026\u2026\u2026\u2026<\/pre>\n\n\n\n

\u4f7f\u7528bzip2\u538b\u7f29\u683c\u5f0f\u5bf9\u67d0\u4e2a\u76ee\u5f55\u8fdb\u884c\u6253\u5305\u64cd\u4f5c\uff0c\u663e\u793a\u538b\u7f29\u8fc7\u7a0b\uff0c\u538b\u7f29\u5305\u89c4\u8303\u540e\u7f00\u4e3a.tar.bz2\uff1a<\/p>\n\n\n\n

[root@linuxcool ~]# tar cjvf backup2.tar.bz2 \/etc<\/strong>\ntar: Removing leading `\/' from member names\n\/etc\/\n\/etc\/mtab\n\/etc\/fstab\n\/etc\/crypttab\n\/etc\/resolv.conf\n\/etc\/dnf\/\n\/etc\/dnf\/modules.d\/\n\/etc\/dnf\/modules.d\/container-tools.module\n\u2026\u2026\u2026\u2026\u2026\u2026\u7701\u7565\u90e8\u5206\u8f93\u51fa\u4fe1\u606f\u2026\u2026\u2026\u2026\u2026\u2026<\/pre>\n\n\n\n

\u5c06\u5f53\u524d\u5de5\u4f5c\u76ee\u5f55\u5185\u6240\u6709\u4ee5.cfg\u4e3a\u540e\u7f00\u7684\u6587\u4ef6\u6253\u5305\uff0c\u4e0d\u8fdb\u884c\u538b\u7f29\uff1a<\/p>\n\n\n\n

[root@linuxcool ~]# tar cvf backup3.tar *.cfg<\/strong>\r\nanaconda-ks.cfg\r\ninitial-setup-ks.cfg<\/pre>\n\n\n\n

\u5c06\u5f53\u524d\u5de5\u4f5c\u76ee\u5f55\u5185\u7684\u6240\u6709\u4ee5.cfg\u4e3a\u540e\u7f00\u7684\u6587\u4ef6\u6253\u5305\uff0c\u4e0d\u8fdb\u884c\u538b\u7f29\uff0c\u5e76\u5220\u9664\u539f\u59cb\u6587\u4ef6\uff1a<\/p>\n\n\n\n

[root@linuxcool ~]# tar cvf backup4.tar *.cfg --remove-files<\/strong>\r\nanaconda-ks.cfg\r\ninitial-setup-ks.cfg\r<\/pre>\n\n\n\n

\u89e3\u538b\u67d0\u4e2a\u538b\u7f29\u5305\u5230\u5f53\u524d\u5de5\u4f5c\u76ee\u5f55\uff1a<\/p>\n\n\n\n

[root@linuxcool ~]# tar xvf backup4.tar <\/strong>\r\nanaconda-ks.cfg\r\ninitial-setup-ks.cfg\r<\/pre>\n\n\n\n

\u89e3\u538b\u67d0\u4e2a\u538b\u7f29\u5305\u5230\/etc\u76ee\u5f55\uff1a<\/p>\n\n\n\n

[root@linuxcool ~]# tar xvf backup4.tar -C \/etc<\/strong>\r\nanaconda-ks.cfg\r\ninitial-setup-ks.cfg\r<\/pre>\n\n\n\n

\u67e5\u770b\u67d0\u4e2a\u538b\u7f29\u5305\u5185\u6587\u4ef6\u4fe1\u606f\uff08\u65e0\u9700\u89e3\u538b\uff09\uff1a<\/p>\n\n\n\n

[root@linuxcool ~]# tar tvf backup4.tar \r\n-rw------- root\/root      1256 2022-05-18 08:42 anaconda-ks.cfg\r\n-rw-r--r-- root\/root      1585 2025-05-18 08:43 initial-setup-ks.cfg\r<\/pre>\n","protected":false},"excerpt":{"rendered":"

tar\u547d\u4ee4\u7684\u529f\u80fd\u662f\u7528\u4e8e\u538b\u7f29\u548c\u89e3\u538b\u7f29\u6587\u4ef6\uff0c\u80fd\u591f\u5236\u4f5c\u51faLinux\u7cfb\u7edf\u4e2d\u5e38\u89c1\u7684.tar\u3001.tar.gz\u3001.tar.b […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/posts\/6722"}],"collection":[{"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/comments?post=6722"}],"version-history":[{"count":15,"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/posts\/6722\/revisions"}],"predecessor-version":[{"id":9158,"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/posts\/6722\/revisions\/9158"}],"wp:attachment":[{"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/media?parent=6722"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/categories?post=6722"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/tags?post=6722"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}