Yan Xu Yan Xu - 7 months ago 27
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?


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'