2016-05-17 7 views
0

ファイルが存在するときに何も表示されないのはなぜですか?findの正規表現での条件

find ./ -regex '.*(jar|war)'

+0

私は混乱していますので、**。**で始まる文字列を見つけて、文字列の末尾に戦争または瓶が付いているものは何ですか? – jgr208

+1

この場合、 '-name '* [jw] ar''で十分です。ありがとう。 –

答えて

2

男性は正規表現のサポートされている構文については、を見つける参照してください:

-regextype type 
     Changes the regular expression syntax understood by -regex and 
     -iregex tests which occur later on the command line. Currently- 
     implemented types are emacs (this is the default), posix-awk, 
     posix-basic, posix-egrep and posix-extended. 

これは動作します:

$ find . -regextype egrep -regex '(.*jar)|(.*war)' 

-regextype変更表現を使用しないようにするにはemacs正規表現に:

$ find . -regex '.*\(jar\|war\)' 
+0

あなたは正しいです – viavad

+1

私は答えにemacsの正規表現を追加したので、-regextype find引数について心配する必要はありません。基本的には、emacs式では、エスケープ括弧とパイプ文字をバックスラッシュで囲む必要があります。 – kbulgrien