14

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
  • The version is GNU 4.4.2. Escaping the slash is just an old habit from perl or somewhere, I guess. – Karl Bielefeldt Oct 25 '14 at 16:21
35

Why do so difficult with -regex? Just do it with -name

find . -type f -name "[[:upper:]]*"

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.