如何在名称中查找带方括号的文件

时间:2022-01-12 21:42:42

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

[ABC]测试file.txt

Regexp I'm trying:

Regexp我正在尝试:

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?

- 工作正常。所以问题在于方括号。有任何想法吗?

1 个解决方案

#1


5  

No matching square brackets is not a problem. Problem is matching the file's path. Remember find's output starts with ./ for the current path.

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

So this regex in your find command will work for you:

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

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

#1


5  

No matching square brackets is not a problem. Problem is matching the file's path. Remember find's output starts with ./ for the current path.

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

So this regex in your find command will work for you:

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

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