The find
command can be used with regular expressions which makes it easy to get any kind of complex search results. How it works:
- You have to use your
find
command with -regex
instead of -name
.
- You have to generate a matching regular expression
How find
passes the filename to the regular expression?
Assume we have the following directory structure:
/home/someone/build/libs/abc.jar
/home/someone/build/libs/abc-plain.jar
and we are sitting in someone
if we execute find .
without any further arguments, we get:
./build/libs/abc.jar
./build/libs/abc-plain.jar
So we can for example search with regex for:
- something starts with a single dot
.
- may have some additional path inside the file name
- should NOT contain the
-
character in any number of character
- ends with
.jar
This results in:
- '.'
- '/*'
- '[^-]+'
- '.jar'
And all together:
find . -regex '.*/[^-]+.jar'
or if you ONLY want to search in build/libs/
find ./build/libs -regex '.*/[^-]+.jar'
You find a online regex tool there.