Reputation: 3378
I have a list of directories where most are in a format like ./[foobar]/
. However, some are formatted like ./[foo] bar/
.
I would like to use find
(or some other utility my shell offers) to find those directories not matching the first pattern (i.e. having text outside the square braces). Until now, I was unable to find a way to "inverse" my pattern.
Any ways to do this?
Upvotes: 1
Views: 5498
Reputation: 70460
find -type d -name '*\]?*'
Unless you insist on opening bracket check...
Upvotes: 1
Reputation: 6186
You could combine find with grep and it's -v option. find . -type d | grep -v "[foobar]"
Upvotes: 3
Reputation: 56059
A simple regular glob will work in this particular example:
$ ls
[a]b [ab]
$ echo \[*\]
[ab]
For more complex patterns you can enable extglob
:
!(pattern-list)
Matches anything except one of the given patterns
Or using find:
find dir ! -name ...
Upvotes: 3
Reputation: 11784
find
supports negation by means of !
and -not
. The latter is not POSIX-compliant. In order to use !
you have to precede it with backslash or put it inside single quotes.
Upvotes: 2