Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to match these file names with the find command:


I'm reasonable familiar with Java-Perl regex syntax. Unfortunately, find only supports emacs and posix syntax.

Even after looking at the emacs syntax I cannot get a basic match to work.

find . -regex "^[[:digit:]]+" -- matches nothing
find . -regex "^[[:digit:]]+.*(ALPHA\|BETA)\.jar" -- matches nothing

This is pretty straightforward in Java and Perl, for example:

ls | grep -P "^\d+.*(ALPHA|BETA)\.jar"


share|improve this question
I added an grep using Perl regex as an example of what I want. – KaizenSoze Nov 9 '11 at 16:53
I can only give one correct answer, though everyone was correct. Thanks. – KaizenSoze Nov 9 '11 at 18:24
For your amusement the complete command:find . -regextype posix-awk -regex ".*/[0-9\-]+CR[0-9]+-R[0-9]+-(ALPHA|BETA)\.jar" ! ( -name *689305* ) -exec java -jar {} --describe \; | grep "^CR" | sort | uniq – KaizenSoze Nov 9 '11 at 18:24
up vote 2 down vote accepted

a regex for matching those files with either posix-awk or posix-extended regxtype would be:

find . -regextype posix-awk -regex ".*/[[:digit:]]+-[[:digit:]]+-[A-Z0-9]+-[A-Z0-9]+-(ALPHA|BETA)\.jar"

because find -regex does matches, not searches

you can specify regex type with -regextype. see the manpage of your find implementation to check what regex engines are supported.

sample (get the files no matter the dir depth):

root@smgw:/tmp# ls -1
root@smgw:/tmp# find . -regextype posix-awk -regex ".*/[[:digit:]]+-[[:digit:]]+-[A-Z0-9]+-[A-Z0-9]+-(ALPHA|BETA)\.jar"

move the jars around, make sure they're still returned

search them with an abs path

root@smgw:/tmp# find /tmp  -regextype posix-awk -regex ".*/[[:digit:]]+-[[:digit:]]+-[A-Z0-9]+-[A-Z0-9]+-(ALPHA|BETA)\.jar"

modified depth:

root@smgw:/tmp# mkdir -p x/y/z
root@smgw:/tmp# cp *^C
root@smgw:/tmp# mv *.jar x/y/z/
root@smgw:/tmp# find /tmp  -regextype posix-awk -regex ".*/[[:digit:]]+-[[:digit:]]+-[A-Z0-9]+-[A-Z0-9]+-(ALPHA|BETA)\.jar"
share|improve this answer

A regex using emacs style to match your pattern could be:


Below is a simple test I've made:

abarbosa@SPF-157:~/Temp/test$ ls -1
abarbosa@SPF-157:~/Temp/test$ find . -regex ".*/[0-9]+-[0-9]+-[0-9A-Z]+-[0-9A-Z]+-\(ALPHA\|BETA\)\.jar$"
share|improve this answer

According to the man find, this is a match on the whole path, not a search. So, you must use something like this:

$ find . -regex .*/[0-9]+.*\.jar

You can also change the regular expression type to posix-awk, posix-basic, posix-extended, ... with the -regextype option.

share|improve this answer
That regex gives me jars that don't start with digits. Imagine there are dozens of jars in the directory, I only want to match the ones that start with 470 something. – KaizenSoze Nov 9 '11 at 16:50
Just insert a leading slash before the 470... Updated my answer. – quanta Nov 9 '11 at 16:52

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.