1.题目
2.参考答案
一般来说这两个参数或命令是一样的。可是在一些情况下尤其是打包压缩的时候差别就很大了。
find /oldboy -type f |xargs find命令找到的文件一次性都给 |xargs 处理
find /oldboy -type f -exec -exec find命令找到一个文件 就传递给 -exec 处理一次
测试方法—-通过打包压缩tar命令进行测试
测试环境
[[email protected] ~]# find /oldboy -type f /oldboy/stu02.txt /oldboy/stu10.txt /oldboy/stu08.txt /oldboy/stu01.txt /oldboy/stu07.txt /oldboy/stu03.txt /oldboy/stu09.txt /oldboy/stu05.txt /oldboy/stu04.txt /oldboy/stu06.txt /oldboy/stu00.txt
测试|xargs
[[email protected] ~]# find /oldboy -type f |xargs tar zcf /tmp/oldboy-xargs.tar.gz tar: Removing leading `/‘ from member names #检查结果 [[email protected] ~]# tar tf /tmp/oldboy-xargs.tar.gz oldboy/stu02.txt oldboy/stu10.txt oldboy/stu08.txt oldboy/stu01.txt oldboy/stu07.txt oldboy/stu03.txt oldboy/stu09.txt oldboy/stu05.txt oldboy/stu04.txt oldboy/stu06.txt oldboy/stu00.txt 结果正常,我们要压缩的文件都在。
测试-exec
[[email protected] ~]# find /oldboy -type f -exec tar zcf /tmp/oldboy-exec.tar.gz {} \;tar: Removing leading `/‘ from member names tar: Removing leading `/‘ from member names tar: Removing leading `/‘ from member names tar: Removing leading `/‘ from member names tar: Removing leading `/‘ from member names tar: Removing leading `/‘ from member names tar: Removing leading `/‘ from member names tar: Removing leading `/‘ from member names tar: Removing leading `/‘ from member names tar: Removing leading `/‘ from member names tar: Removing leading `/‘ from member names [[email protected] ~]# tar tf /tmp/oldboy-exec.tar.gz oldboy/stu00.txt ###奇怪为何会这样呢?压缩包中只有一个文件了。
解释
find /oldboy -type f |xargs tar zcf /tmp/oldboy-xargs.tar.gz 相当于 tar zcf /tmp/oldboy-xargs.tar.gz /oldboy/stu02.txt /oldboy/stu10.txt /oldboy/stu08.txt /oldboy/stu01.txt /oldboy/stu07.txt /oldboy/stu03.txt /oldboy/stu09.txt /oldboy/stu05.txt /oldboy/stu04.txt /oldboy/stu06.txt /oldboy/stu00.txt
find /oldboy -type f -exec tar zcf /tmp/oldboy-exec.tar.gz {} \; 相当于 tar zcf /tmp/oldboy-exec.tar.gz /oldboy/stu02.txt tar zcf /tmp/oldboy-exec.tar.gz /oldboy/stu10.txt tar zcf /tmp/oldboy-exec.tar.gz /oldboy/stu08.txt tar zcf /tmp/oldboy-exec.tar.gz /oldboy/stu01.txt tar zcf /tmp/oldboy-exec.tar.gz /oldboy/stu07.txt tar zcf /tmp/oldboy-exec.tar.gz /oldboy/stu03.txt tar zcf /tmp/oldboy-exec.tar.gz /oldboy/stu09.txt tar zcf /tmp/oldboy-exec.tar.gz /oldboy/stu05.txt tar zcf /tmp/oldboy-exec.tar.gz /oldboy/stu04.txt tar zcf /tmp/oldboy-exec.tar.gz /oldboy/stu06.txt tar zcf /tmp/oldboy-exec.tar.gz /oldboy/stu00.txt 相当于执行了很多次,打包压缩的命令而且压缩包名字都一样,所以会不断的覆盖。
3.统计信息
今天是每日一题陪伴大家的第54天,期待你的进步。
对于题目和答案的任何疑问,请在博客评论区留言。
往期题目索引
http://lidao.blog.51cto.com/3388056/1914205
时间: 2024-09-30 07:12:03