温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

如何进行tar打包且排除某个文件

发布时间:2021-11-04 18:22:13 来源:亿速云 阅读:720 作者:柒染 栏目:建站服务器

这篇文章给大家介绍如何进行tar打包且排除某个文件,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。

有tar打包,有时候需要排除某个文件,本文档提供两种方法来操作。

方法一

[root@system1 testdir]# touch 1 2 3 4 5 6 7 b
[root@system1 testdir]# ls
1  2  3  4  5  6  7  b
[root@system1 testdir]# tar zcvf a.tar.gz ./* --exclude b
#排除b文件
./1
./2
./3
./4
./5
./6
./7
[root@system1 testdir]# ls
1  2  3  4  5  6  7  a.tar.gz  b
[root@system1 testdir]# mv a.tar.gz /tmp/test
[root@system1 testdir]# ls
1  2  3  4  5  6  7  b
[root@system1 testdir]# cd ..
[root@system1 tmp]# cd test
[root@system1 test]# ls
a.tar.gz
[root@system1 test]# tar -xvf a.tar.gz 
./1
./2
./3
./4
./5
./6
./7
[root@system1 test]# ls
1  2  3  4  5  6  7  a.tar.gz

方法二

[root@system1 testdir]# ls
1  2  3  4  5  6  7  b
[root@system1 testdir]# find ./ -type f ! -name 'b'  | xargs tar caf a.tar.gz
#排除b文件
[root@system1 testdir]# ls
1  2  3  4  5  6  7  a.tar.gz  b
[root@system1 testdir]# mv a.tar.gz /tmp/test
[root@system1 testdir]# cd /tmp/test
[root@system1 test]# ls
a.tar.gz
[root@system1 test]# tar -xvf a.tar.gz 
./1
./2
./3
./4
./5
./6
./7
[root@system1 test]# ls
1  2  3  4  5  6  7  a.tar.gz

关于如何进行tar打包且排除某个文件就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

tar
AI