2008-08-20 66 views
17

我在尋找安裝在我的系統shell腳本文件,但發現不起作用:爲什麼不找**找到任何東西?

$ find /usr -name *.sh 

但我知道有一噸的腳本在那裏。例如:

$ ls /usr/local/lib/*.sh 
/usr/local/lib/tclConfig.sh 
/usr/local/lib/tkConfig.sh 

爲什麼不找到工作?

+2

這是一個超級用戶問題? – endolith 2009-11-08 01:44:11

+0

這更適合於[UnixSE](http://unix.stackexchange.com/) – 2015-12-17 10:17:21

回答

51

嘗試引用通配符:

$ find /usr -name \*.sh 

或:

$ find /usr -name '*.sh' 

如果你碰巧有一個匹配* .SH在當前工作目錄文件,通配符將擴大在找到它之前。如果你碰巧有一個在你的工作目錄中名爲tkConfig.sh文件時,找到命令將擴展爲:

$ find /usr -name tkConfig.sh 

這隻會查找文件名爲tkConfig.sh。如果你有一個匹配* .SH多個文件,你會得到語法錯誤發現

$ cd /usr/local/lib 
$ find /usr -name *.sh 
find: bad option tkConfig.sh 
find: path-list predicate-list 

再次,原因是通配符擴展到這兩個文件:

$ find /usr -name tclConfig.sh tkConfig.sh 

引用通配符可防止過早擴展。

另一種可能性是/ usr或其子目錄之一是符號鏈接。 發現沒有正常跟隨鏈接,所以你可能需要-follow選項:

$ find /usr -follow -name '*.sh' 
+0

如果文件是shell腳本但缺少`.sh`擴展名會怎麼樣?也許像`find/xyz | xargs文件| grep shell`? – 2015-12-14 17:52:12

+0

雖然shell腳本**不具有.sh擴展名的頻率多高? – 2015-12-16 19:43:46

15

在某些系統(Solaris中,例如),沒有默認的動作,所以你需要添加 - 打印命令。

find /usr -name '*.foo' -print 
7

對於磁盤上的查找文件,精益使用「定位」,而不是說是瞬間 (看起來變成了一種日常內置指數) 你的例子是:

locate '/usr*.sh' 
相關問題