2016-06-26 7 views
0

で検索します。ディレクトリの下にファイル名にアンダースコアのファイルがあります。私はそのようなファイルを取得し、それらを画面上に印刷したい。ファイル名にアンダースコアのないファイルを正規表現

find ./ -type f -name '[a-z0-9]*\.java' 

しかし、私はまだ画面上のファイル./a_b.javaを取得することができます:私が使用 コマンドがあります。 私の正規表現に何が間違っているのか教えてください。

答えて

0

これは正規表現ではなく、パターンです。 *は、ls *のように「任意の文字」を意味します。実際に正規表現を使用するには-nameの代わりに-regexを使用しますが、ファイル名だけでなくパス全体に一致する必要があります。 find

find . -type f -regex '.*/[a-z0-9]*\.java' 
0

-nameglobパターンです。あなたがわからないときは、マニュアルページを確認してください:

-name pattern 
      Base of file name (the path with the leading directories removed) matches shell pattern pattern. Because the leading directories are 
      removed, the file names considered for a match with -name will never include a slash, so `-name a/b' will never match anything (you probably 
      need to use -path instead). A warning is issued if you try to do this, unless the environment variable POSIXLY_CORRECT is set. The 
      metacharacters (`*', `?', and `[]') match a `.' at the start of the base name (this is a change in findutils-4.2.2; see section STANDARDS 
      CONFORMANCE below). To ignore a directory and the files under it, use -prune; see an example in the description of -path. Braces are not 
      recognised as being special, despite the fact that some shells including Bash imbue braces with a special meaning in shell patterns. The 
      filename matching is performed with the use of the fnmatch(3) library function. Don't forget to enclose the pattern in quotes in order to 
      protect it from expansion by the shell. 
関連する問題