I'm trying to find all files for which there name starts with a capital letter. I have tried using the following command:

find . -type f -regex '.*\/[A-Z][^/]*'

It's finding paths with only lowercase letters. The following works:

find . -type f -regex '.*\/[ABCDEFGHIJKLMNOPQRSTUVWXYZ][^/]*'

As does:

find . -type f | grep '.*\/[A-Z][^/]*$'

I've tried all the different options for regextype, with the same result.

Why does find include lowercase letters in [A-Z]? I thought the regex for that was [a-zA-Z]. Is there any way to specify a range of only uppercase letters in find?

  • 5
    What about LC_ALL=C find ...? – mikeserv Oct 25 '14 at 15:12
  • That works. Could you explain why in an answer? – Karl Bielefeldt Oct 25 '14 at 15:14
  • 3
    I could try, but then you might miss out on this. – mikeserv Oct 25 '14 at 15:18
  • 1
    Why are you escaping the slash (\/)? Also what find are you using (find --version)? – Cristian Ciupitu Oct 25 '14 at 16:16
  • 1
    Escaping / is only necessary when you're using it as a delimiter, e.g. in s/foo\/bar/foobar/. (But often you can use some other delimiter: s#foo/bar#foobar#.) – deltab Oct 26 '14 at 4:32

You don't need to use -regex. You can use -name instead.

find . -type f -name "[[:upper:]]*"
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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