2014-07-18 46 views
3

我有一個目錄a/b/c.js如何讓ack忽略目錄中的文件?

文件我不能忽視c.js--ignore-file=match:c.js因爲我想匹配名爲c.js

我不能--ignore-dir=a/b因爲有其他文件忽略目錄a/b其他文件我關心a/b

我已經試過:

--ignore-file=a/b/c.js  "Invalid filter specification" 

我已經試過:

--ignore-file=match:/a\/b\/c.js/ 

不工作,我猜這是因爲ACK並不讀取文件路徑作爲比賽的一部分,只是名字。

我已經試過:

--ignore-dir=match:/a\/b\/c.js/  " Non-is filters are not yet supported for --ignore-dir (what?)" 

我無法找到任何東西在Ack manual湯有用。如何忽略目錄中的文件?

回答

1

您可以使用find ... ! -path ...輕鬆搜索與給定路徑匹配的文件而不是

此外,find ... -exec ... \{} \+允許啓動一個帶有附加文件列表的命令。

我沒有ack在手,但使用grep作爲一個佔位符,這將導致:

sh$ echo toto > a/b/c.js 
sh$ echo toto > a/c.js 
sh$ echo toto > a/b/x.js 
sh$ find . \! -path './a/b/c.js' -type f -exec grep toto \{} \+ 
#  ^  ^      ^^^^ 
#  pattern should match    replace by a call to `ack` 
#  your search path 
./a/c.js:toto 
./a/b/x.js:toto 

編輯:有在開始與./一個潛在的缺陷路徑模式。 你可能更喜歡使用find ... ! -samefile ...拒絕具有相同的inode爲給定的文件找到的文件:

sh$ find . \! -samefile a/b/c.js -type f -exec grep toto \{} \+ 
#      ^^^^^^^^ 
#     no dot here; this is a *file* 
#     can't use glob patterns (*, ?, ...) 
./a/c.js:toto 
./a/b/x.js:toto 

man find

! expr True if expr is false. This character will also usually need 
      protection from interpretation by the shell. 

    -path pattern 
      File name matches shell pattern pattern. The metacharacters do 
      not treat `/' or `.' specially; so, for example, 
        find . -path "./sr*sc" 
      [...] 

    -samefile name 
      File refers to the same inode as name. When -L is in effect, 
      this can include symbolic links.