如何查找名称中带有方括号的文件 [英] How to find files with square brackets in the name
本文介绍了如何查找名称中带有方括号的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的文件命名是这样的:
[ABC] test file.txt
正则表达式我试图:
find。 -iregex'\ [abc\]。* test。*'
似乎工作出于某种原因。如果我将它替换为 -
find。 -iregex'。* abc。* test。*'
- 可以正常工作。所以问题在于方括号。任何想法?
解决方案
没有匹配的方括号不是问题。问题是匹配文件的路径。记住find的输出以 ./
作为当前路径。
所以find命令中的这个正则表达式适用于你:
find。 -iregex'\。/ \ [abc\]。* test。*'
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?
解决方案
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.
So this regex in your find command will work for you:
find . -iregex '\./\[abc\].*test.*'
这篇关于如何查找名称中带有方括号的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文