简体   繁体   English

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

[英]How to find files with square brackets in the name

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: 正则表达式我正在尝试:

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? 有任何想法吗?

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.*'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM