5

I'm trying to find some files with square brackets, but I can't seem to get it to work.

My files are named are this:

[ABC] test file.txt

Regexp I'm trying:

find . -iregex '\[abc\].*test.*'

That just doesn't seem to work for some reason. If i replace it with -

find . -iregex '.*abc.*test.*'

-it works fine. So the problem is with the square brackets. Any ideas?

4

1 回答 1

5

没有匹配的方括号不是问题。问题是匹配文件的路径。请记住 find 的输出以./当前路径开头。

所以你的 find 命令中的这个正则表达式对你有用:

find . -iregex '\./\[abc\].*test.*'
于 2013-07-08T13:44:33.443 回答