共计 6737 个字符,预计需要花费 17 分钟才能阅读完成。
提醒:本文最后更新于2019-07-11 23:02,文中所关联的信息可能已发生改变,请知悉!
[v_act]格式:tar [OPTION…] [FILE]…
-c:新建打包文件
-x:解开打包(压缩)文件
-z:以gzip的方式压缩打包文件(.tar.gz);需已安装gzip包
-j:以bzip2的方式压缩打包文件(.tar.bz2);需已安装bzip2包
-J:以xz的方式压缩打包文件(.tar.xz);需已安装xz包
-t:查看打包(压缩)文件内的目录文件
-f:指定文件名称
–exclude=FileName(DirName):打包压缩操作时排除指定的目录或文件;排除目录时被排除的目录后不能有“/”结尾
-C /PATH/DirName:解压至指定路径
实例:
–czf 压缩包文件.tar.gz 被打包压缩目录文件:以gzip的方式压缩打包目录文件
–cjf 压缩包文件.tar.bz2 被打包压缩目录文件:以bzip2的方式压缩打包目录文件
–cJf 压缩包文件.tar.xz 被打包压缩目录文件:以xz的方式压缩打包目录文件
–xf 压缩包文件.tar.gz:解开指定打包(压缩)文件
–tf 压缩包文件.tar.gz:查看指定打包(压缩)文件内的目录文件[/v_act]
–czf 压缩包文件.tar.gz 被打包压缩目录文件:以gzip的方式压缩打包目录文件
–cjf 压缩包文件.tar.bz2 被打包压缩目录文件:以bzip2的方式压缩打包目录文件
–cJf 压缩包文件.tar.xz 被打包压缩目录文件:以xz的方式压缩打包目录文件
–cjf 压缩包文件.tar.bz2 被打包压缩目录文件:以bzip2的方式压缩打包目录文件
–cJf 压缩包文件.tar.xz 被打包压缩目录文件:以xz的方式压缩打包目录文件
[root@bogon tmp]# ll
total 0
-rw-r--r-- 1 root root 0 Jul 11 22:54 test10.txt
-rw-r--r-- 1 root root 0 Jul 11 22:54 test1.txt
-rw-r--r-- 1 root root 0 Jul 11 22:54 test2.txt
-rw-r--r-- 1 root root 0 Jul 11 22:54 test3.txt
-rw-r--r-- 1 root root 0 Jul 11 22:54 test4.txt
-rw-r--r-- 1 root root 0 Jul 11 22:54 test5.txt
-rw-r--r-- 1 root root 0 Jul 11 22:54 test6.txt
-rw-r--r-- 1 root root 0 Jul 11 22:54 test7.txt
-rw-r--r-- 1 root root 0 Jul 11 22:54 test8.txt
-rw-r--r-- 1 root root 0 Jul 11 22:54 test9.txt
[root@bogon tmp]# tar -czf test.tar.gz test*.txt
[root@bogon tmp]# ll
total 4
-rw-r--r-- 1 root root 0 Jul 11 22:54 test10.txt
-rw-r--r-- 1 root root 0 Jul 11 22:54 test1.txt
-rw-r--r-- 1 root root 0 Jul 11 22:54 test2.txt
-rw-r--r-- 1 root root 0 Jul 11 22:54 test3.txt
-rw-r--r-- 1 root root 0 Jul 11 22:54 test4.txt
-rw-r--r-- 1 root root 0 Jul 11 22:54 test5.txt
-rw-r--r-- 1 root root 0 Jul 11 22:54 test6.txt
-rw-r--r-- 1 root root 0 Jul 11 22:54 test7.txt
-rw-r--r-- 1 root root 0 Jul 11 22:54 test8.txt
-rw-r--r-- 1 root root 0 Jul 11 22:54 test9.txt
-rw-r--r-- 1 root root 188 Jul 11 22:54 test.tar.gz
[root@bogon tmp]# tar -cjf test.tar.bz2 test*.txt
[root@bogon tmp]# ll
total 8
-rw-r--r-- 1 root root 0 Jul 11 22:54 test10.txt
-rw-r--r-- 1 root root 0 Jul 11 22:54 test1.txt
-rw-r--r-- 1 root root 0 Jul 11 22:54 test2.txt
-rw-r--r-- 1 root root 0 Jul 11 22:54 test3.txt
-rw-r--r-- 1 root root 0 Jul 11 22:54 test4.txt
-rw-r--r-- 1 root root 0 Jul 11 22:54 test5.txt
-rw-r--r-- 1 root root 0 Jul 11 22:54 test6.txt
-rw-r--r-- 1 root root 0 Jul 11 22:54 test7.txt
-rw-r--r-- 1 root root 0 Jul 11 22:54 test8.txt
-rw-r--r-- 1 root root 0 Jul 11 22:54 test9.txt
-rw-r--r-- 1 root root 185 Jul 11 22:57 test.tar.bz2
-rw-r--r-- 1 root root 188 Jul 11 22:54 test.tar.gz
[root@bogon tmp]# tar -cJf test.tar.xz test*.txt
[root@bogon tmp]# ll
total 12
-rw-r--r-- 1 root root 0 Jul 11 22:54 test10.txt
-rw-r--r-- 1 root root 0 Jul 11 22:54 test1.txt
-rw-r--r-- 1 root root 0 Jul 11 22:54 test2.txt
-rw-r--r-- 1 root root 0 Jul 11 22:54 test3.txt
-rw-r--r-- 1 root root 0 Jul 11 22:54 test4.txt
-rw-r--r-- 1 root root 0 Jul 11 22:54 test5.txt
-rw-r--r-- 1 root root 0 Jul 11 22:54 test6.txt
-rw-r--r-- 1 root root 0 Jul 11 22:54 test7.txt
-rw-r--r-- 1 root root 0 Jul 11 22:54 test8.txt
-rw-r--r-- 1 root root 0 Jul 11 22:54 test9.txt
-rw-r--r-- 1 root root 185 Jul 11 22:57 test.tar.bz2
-rw-r--r-- 1 root root 188 Jul 11 22:54 test.tar.gz
-rw-r--r-- 1 root root 220 Jul 11 22:57 test.tar.xz
–xf 压缩包文件.tar.gz:解开指定打包(压缩)文件
[root@localhost ~]# ll
total 8444
-rw-------. 1 root root 1301 Feb 10 2017 anaconda-ks.cfg
-rw-r--r-- 1 root root 0 Feb 10 2017 test.txt
-rw-r--r-- 1 root root 8641732 Dec 27 01:32 wordpress.tar.gz
[root@localhost ~]# tar -xf wordpress.tar.gz
[root@localhost ~]# ll
total 8448
-rw-------. 1 root root 1301 Feb 10 2017 anaconda-ks.cfg
-rw-r--r-- 1 root root 0 Feb 10 2017 test.txt
drwxr-xr-x 5 nobody 65534 4096 Aug 4 15:54 wordpress
-rw-r--r-- 1 root root 8641732 Dec 27 01:32 wordpress.tar.gz
–tf 压缩包文件.tar.gz:查看指定打包(压缩)文件内的目录文件
[root@localhost tmp]# tar -tf tmp.tar.gz
tmp/
tmp/test1.txt
tmp/test2.txt
tmp/test.txt
–exclude=FileName(DirName):打包压缩操作时排除指定的目录或文件;排除目录时被排除的目录后不能有“/”结尾
[root@bogon tmp]# ll
total 4
-rw-r--r-- 2 root root 53 Jul 9 21:57 2-hard
drwx------ 3 root root 17 Jul 11 21:24 systemd-private-d4c61ffaa1a944c797d375fef8906950-chronyd.service-984xts
drwx------ 2 root root 6 Jul 11 21:24 vmware-root_8623-1990534217
drwx------ 2 root root 6 Jul 10 22:06 vmware-root_8632-995670400
drwx------ 2 root root 6 Jul 9 21:24 vmware-root_8639-1957503577
[root@bogon tmp]# touch test{1..10}.txt
[root@bogon tmp]# ll
total 4
-rw-r--r-- 2 root root 53 Jul 9 21:57 2-hard
drwx------ 3 root root 17 Jul 11 21:24 systemd-private-d4c61ffaa1a944c797d375fef8906950-chronyd.service-984xts
-rw-r--r-- 1 root root 0 Jul 11 22:30 test10.txt
-rw-r--r-- 1 root root 0 Jul 11 22:30 test1.txt
-rw-r--r-- 1 root root 0 Jul 11 22:30 test2.txt
-rw-r--r-- 1 root root 0 Jul 11 22:30 test3.txt
-rw-r--r-- 1 root root 0 Jul 11 22:30 test4.txt
-rw-r--r-- 1 root root 0 Jul 11 22:30 test5.txt
-rw-r--r-- 1 root root 0 Jul 11 22:30 test6.txt
-rw-r--r-- 1 root root 0 Jul 11 22:30 test7.txt
-rw-r--r-- 1 root root 0 Jul 11 22:30 test8.txt
-rw-r--r-- 1 root root 0 Jul 11 22:30 test9.txt
drwx------ 2 root root 6 Jul 11 21:24 vmware-root_8623-1990534217
drwx------ 2 root root 6 Jul 10 22:06 vmware-root_8632-995670400
drwx------ 2 root root 6 Jul 9 21:24 vmware-root_8639-1957503577
[root@bogon tmp]# tar -czf test.tar.gz --exclude=test5.txt test*.txt
[root@bogon tmp]# ll
total 8
-rw-r--r-- 2 root root 53 Jul 9 21:57 2-hard
drwx------ 3 root root 17 Jul 11 21:24 systemd-private-d4c61ffaa1a944c797d375fef8906950-chronyd.service-984xts
-rw-r--r-- 1 root root 0 Jul 11 22:30 test10.txt
-rw-r--r-- 1 root root 0 Jul 11 22:30 test1.txt
-rw-r--r-- 1 root root 0 Jul 11 22:30 test2.txt
-rw-r--r-- 1 root root 0 Jul 11 22:30 test3.txt
-rw-r--r-- 1 root root 0 Jul 11 22:30 test4.txt
-rw-r--r-- 1 root root 0 Jul 11 22:30 test5.txt
-rw-r--r-- 1 root root 0 Jul 11 22:30 test6.txt
-rw-r--r-- 1 root root 0 Jul 11 22:30 test7.txt
-rw-r--r-- 1 root root 0 Jul 11 22:30 test8.txt
-rw-r--r-- 1 root root 0 Jul 11 22:30 test9.txt
-rw-r--r-- 1 root root 182 Jul 11 22:31 test.tar.gz
drwx------ 2 root root 6 Jul 11 21:24 vmware-root_8623-1990534217
drwx------ 2 root root 6 Jul 10 22:06 vmware-root_8632-995670400
drwx------ 2 root root 6 Jul 9 21:24 vmware-root_8639-1957503577
[root@bogon tmp]# tar -tf test.tar.gz
test10.txt
test1.txt
test2.txt
test3.txt
test4.txt
test6.txt
test7.txt
test8.txt
test9.txt
[root@bogon tmp]#
[root@bogon tmp]# ll
total 4
-rw-r--r-- 2 root root 53 Jul 9 21:57 2-hard
drwx------ 3 root root 17 Jul 11 21:24 systemd-private-d4c61ffaa1a944c797d375fef8906950-chronyd.service-984xts
drwx------ 2 root root 6 Jul 11 21:24 vmware-root_8623-1990534217
drwx------ 2 root root 6 Jul 10 22:06 vmware-root_8632-995670400
drwx------ 2 root root 6 Jul 9 21:24 vmware-root_8639-1957503577
[root@bogon tmp]# tar -czf vmware-root.tar.gz --exclude=vmware-root_8632-995670400 vmware-root*
[root@bogon tmp]# ll
total 8
-rw-r--r-- 2 root root 53 Jul 9 21:57 2-hard
drwx------ 3 root root 17 Jul 11 21:24 systemd-private-d4c61ffaa1a944c797d375fef8906950-chronyd.service-984xts
drwx------ 2 root root 6 Jul 11 21:24 vmware-root_8623-1990534217
drwx------ 2 root root 6 Jul 10 22:06 vmware-root_8632-995670400
drwx------ 2 root root 6 Jul 9 21:24 vmware-root_8639-1957503577
-rw-r--r-- 1 root root 152 Jul 11 22:36 vmware-root.tar.gz
[root@bogon tmp]# tar -tf vmware-root.tar.gz
vmware-root_8623-1990534217/
vmware-root_8639-1957503577/
[root@bogon tmp]#
-C /PATH/DirName:解压至指定路径
[root@bogon tmp]# ll /root/
total 8
-rw-r--r-- 2 root root 53 Jul 9 21:57 2
-rw-------. 1 root root 1456 Jan 15 10:46 anaconda-ks.cfg
[root@bogon tmp]# tar -xf vmware-root.tar.gz -C /root/
[root@bogon tmp]# ll /root/
total 8
-rw-r--r-- 2 root root 53 Jul 9 21:57 2
-rw-------. 1 root root 1456 Jan 15 10:46 anaconda-ks.cfg
drwx------ 2 root root 6 Jul 11 21:24 vmware-root_8623-1990534217
drwx------ 2 root root 6 Jul 9 21:24 vmware-root_8639-1957503577
[root@bogon tmp]#
正文完