linux find命令忽略某個(gè)或多個(gè)子目錄的實(shí)例
使用find命令在linux系統(tǒng)中查找文件時(shí),有時(shí)需要忽略某些目錄,可以使用 -prune 參數(shù)來進(jìn)行過濾。
不過必須注意:要忽略的路徑參數(shù)要緊跟著搜索的路徑之后,否則該參數(shù)無法起作用。
例如:指定搜索/home/zth目錄下的所有文件,但是會(huì)忽略/home/zth/astetc的路徑:
find /home/zth -path "/home/zth/astetc" -prune -o -type f -print
按照文件名來搜索則為:
find /home/zth -path "/home/zth/astetc" -prune -o -type f -name "cdr_*.conf" -print
要忽略兩個(gè)以上的路徑如何處理?
find /home/zth /( -path "/home/zth/astetc" -o -path "/home/zth/etc" /) -prune -o -type f -print
find /home/zth /( -path "/home/zth/astetc" -o -path "/home/zth/etc" /) -prune -o -type f -name "cdr_*.conf" -print
注意:/( 和/) 前后都有空格。
查找某個(gè)文件包含內(nèi)容,以下語句可以解決目錄帶空格的問題:
find ./ -name "mysql*" -print0 |xargs -0 grep "SELECT lead_id FROM vicidial_list where vendor_lead_code"
如果目錄不帶空格,可以這樣:
find ./ -name "mysql*" |xargs grep "SELECT lead_id FROM vicidial_list where vendor_lead_code"
通過以上的例子,大家應(yīng)該可以掌握find命令查找文件時(shí),忽略相關(guān)目錄的方法了。
版權(quán)聲明:本站文章來源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請保持原文完整并注明來源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非www.sddonglingsh.com所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學(xué)習(xí)參考,不代表本站立場,如有內(nèi)容涉嫌侵權(quán),請聯(lián)系alex-e#qq.com處理。