Yan Xu Yan Xu - 1 year ago 112
Linux Question

Find files without underscore in their filename with regex

Under a directory, there are files with underscore in their filenames. I want to get such files and print them on screen.
The command I used is:

find ./ -type f -name '[a-z0-9]*\.java'

But I can still get the file
on screen.
Could you tell me what's wrong with my regex?

Answer Source

It's not a regex, it's a pattern. * means "any characters", as in ls *. Use -regex instead of -name to actually use a regex, but note that it has to match the whole path, not just the filename.

find . -type f -regex '.*/[a-z0-9]*\.java'
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download