I have a find command to find a jar file based on a glob pattern I am working on. However, it is not yielding any results. The pattern of the file name looks like this: lib-core-x.x.x.jar where x can be a one or two digit number. I need a POSIX compliant way to match the last digit, which can be a number between 0-99.
Code:
find /usr/share -maxdepth 5 -path '*/lib-core-*.*.[[:digit:]].jar'
Example String:
lib-core-2.15.20.jar
This works if the last number is single digits, but not double digits.
CodePudding user response:
You're trying to use a regular expression in a glob pattern, which doesn't work.
You could use two glob patterns separated with -o, one for 1-digit numbers, the other for 2-digit numbers.
And since you're just matching the filename part, use -name rather than -path.
find /usr/share -maxdepth 5 \( -name 'lib-core-*.*.[0-9].jar' -o -name 'lib-core-*.*.[1-9][0-9].jar' \)
CodePudding user response:
Initially i'd say that you probably want to use -name instead of -path, which matches against the file's basename (seeing as you've prefixed your -path with */). But seeing as your problem is regexpattern related (and -path doesnt do regex) and you want posix compliance, you likely want to look into:
find -regextype posix-egrep -regex .....
