0

名前が特定のC++ファイル拡張子に一致するすべてのファイルを検索しようとしていますが、次のパターンに一致する特定のディレクトリを除外しています。

find /home/palchan/code -name "*.[CcHh]" -o -name "*.cpp" -o -name "*.hpp" -a ! -name "*pattern*"

そしてこれはまだ私に次のような特定のファイルを出力として与えます:

/home/palchan/code/libFox/pattern/hdr/fox/RedFox.H

どちらにパターンがありますか?

次に例を示します。

> ls -R .
.:
libFox

./libFox:
RedFox.C  RedFox.H  pattern

./libFox/pattern:
RedFox.C  RedFox.H

そして、私は実行します:

> find . \( -name "*.[HC]" -a ! -name "*pattern*" \)
./libFox/pattern/RedFox.C
./libFox/pattern/RedFox.H
./libFox/RedFox.C
./libFox/RedFox.H
4

2 に答える 2

1

以下が機能するはずです。

find /home/palchan/code \( -name "*pattern*" \) -prune -o -type f \( -name "*.[CcHh]" -o -name "*.cpp" -o -name "*.hpp" \) -print

差出人man find

 -name pattern
          Base of file name (the path with the leading directories removed) matches shell pattern pattern.  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.

したがって、基本的には、-prune代わりにディレクトリを除外するために使用する必要があります! -name something

于 2013-02-06T02:33:21.803 に答える
0

これを試してみてください:

find /home/palchan/code \( -name "*.[CcHh]" -o -name "*.cpp" -o -name "*.hpp" -a ! -name "*pattern*" \)
于 2013-02-06T00:54:26.973 に答える