linux find 命令忽略某個或多個子目錄的方法 【轉】__linux

來源:互聯網
上載者:User

文章來源:linux find 命令忽略某個或多個子目錄的方法

文章參考:使用find尋找檔案的時候怎麼避開某個檔案目錄


在linux find 進行尋找的時候,有時候需要忽略某些目錄不尋找,可以使用 -prune 參數來進行過濾,但必須要注意要忽略的路徑參數必須緊跟著搜尋的路徑之後,否則該參數無法起作用。

以下是指定搜尋/home/carryf目錄下的所有檔案,但是會忽略/home/carryf/astetc的路徑:

find /home/carryf -path "/home/carryf/astetc" -prune -o -type f -print

 

如果按照檔案名稱來搜尋則為:

find /home/carryf -path "/home/carryf/astetc" -prune -o -type f -name "cdr_*.conf" -print

 

如果要忽略兩個以上的路徑如何處理。

find /home/carryf /( -path "/home/carryf/astetc" -o -path "/home/carryf/etc" /) -prune -o -type f  -print

find /home/carryf /( -path "/home/carryf/astetc" -o -path "/home/carryf/etc" /) -prune -o -type f  -name "cdr_*.conf" -print

注意/( 和/) 前後都有空格。

 

# 由於編輯器原因,所以下面命令使用的是中文括弧。如要使用請把中文的括弧,替換為英文括弧[zhang@zhang zhangliang]$ find ./ \( -path "./20170406" -o -path "./20170525" -o -path "./20170406-02" \) -prune -o -type f -print | xargs -I{} ls -lh {}


 尋找某個檔案包含內容,下面這個語句可以解決目錄帶空格的問題:

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"




聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.