老男孩教育每日一題-2017年5月19日-使用find命令的時候 |xargs(管道xargs)與-exe有什麽區別?
1.題目
老男孩教育每日一題-2017年5月19日-使用find命令的時候 |xargs(管道xargs)與-exe有什麽區別?
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]
解釋
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
本文出自 “李導的博客” 博客,請務必保留此出處http://lidao.blog.51cto.com/3388056/1927694
老男孩教育每日一題-2017年5月19日-使用find命令的時候 |xargs(管道xargs)與-exe有什麽區別?