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?
File names can contain any of the following characters: A-Z, a-z, 0-9, underscore, hyphen, space, period, parenthesis, curly braces, square brackets, tilde, exclamation point, comma, semicolon, apostrophe, at sign, number sign, dollar sign, percent sign, plus sign, and equal sign.
Square brackets are used, usually in books and articles, when supplying words that make a quotation clearer or that comment on it, although they were not originally said or written.
Since the grep process itself has "firefox" in it, grep finds that as well. By adding a [] , we are only searching for the character class "[f]" (which consists of only the letter "f" and is therefor equivalent to just an "f" without the brackets).
square bracket in British English Brackets (also called parentheses) are used to enclose a word or words which can be left out and still leave a meaningful sentence.
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.*'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With