0

I have problem with find and regular expression. I would like to find files in /etc, which name begin of a or b. I tried this commands:

find /etc -type f -regex '^a'
find /etc -regextype sed -regex "^a"
find /etc -regextype egrep -regex '^a'
find /etc -regextype posix-egrep -regex '^a'

But not working. I have 20 files in /etc which name begin of a, but my regexp not find this files. What i do wrong?

Regards Paweł

PawelC
  • 149
  • 1
  • 11

2 Answers2

4

-regex matches the complete path, not the filename only.

The closest thing I came up with would be:

find /etc -type f  -regex '.+/[ab][^/]+'

This matches a /, followed by a or b, followed by everything which is not another /.

Gerald Schneider
  • 23,274
  • 8
  • 57
  • 89
1

This used to be very simple, with:

find /etc -type f -name 'a*'
Gerard H. Pille
  • 2,569
  • 1
  • 13
  • 11