2010-12-11 93 views

回答

3

您可以使用發現:

find -name '*.txt' -exec head {} \; 
0

另一種選擇是使用 -

find -name '*.txt' | xargs head 

請注意,-name不需要在所有環境 工作這種情況下,您可以使用

find . | grep ".txt" | xargs head 
+2

我從來沒有聽說過'-name'不工作,但'find'用你的第二種形式(至少在舊版本中)抱怨失蹤參數並不罕見。 – 2010-12-11 15:10:58

1

如果你的外殼支持的話(zsh的呢,不知道剩下的),你可以使用**語法:

head **/*.txt 
+1

這也支持Bash 4與'shopt -s globstar'或'ksh'與'set -o globstar'。 – 2010-12-11 15:13:14

0

我試圖做同樣的事情;這裏是我的工作(我輸出的文件headtest.txt響應)。請注意,這將通過當前目錄和子目錄。

find . -type f -exec head '{}' \; >> headtest.txt 

希望這會有所幫助。

相關問題