2017-07-26 90 views
2

我正在使用'find'來獲取名爲「out」的dir的路徑,並且希望它在找到後停止查找。該目錄中可能有350G的文件,所以我真的希望它一旦找到就停止查找。如何在找到第一個結果後停止搜索?

這工作BU不停止尋找,花費的時間太長..

find . -type d -name out 

這種 「ungreedy」 方法也適用,但似乎並沒有停止要麼...

find . -type d -regex ".+/out/?" 

我在Perl中運行這個,所以我想我可以編寫一個遞歸函數來讀取目錄樹並做我想要的。但是,一旦發現第一個實例,我是否可以申請「找到」制動器?

在此先感謝!

+1

檢查此:https://unix.stackexchange.com/questions/62880/how-to-stop-the-find-command-after-first-match – user2464424

回答

2

使用-quit

find . -type d -name out -print -quit 

手冊 「查找」 工具here

+0

它不適用於我(在Mac上),但'-print -quit'確實! – alfasin

+0

是的,我錯過了'-print' –

相關問題