16

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?

8
  • 5
    What about LC_ALL=C find ...? Commented Oct 25, 2014 at 15:12
  • That works. Could you explain why in an answer? Commented Oct 25, 2014 at 15:14
  • 3
    I could try, but then you might miss out on this. Commented Oct 25, 2014 at 15:18
  • 1
    Why are you escaping the slash (\/)? Also what find are you using (find --version)? Commented Oct 25, 2014 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#.) Commented Oct 26, 2014 at 4:32

1 Answer 1

43

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

find . -type f -name "[[:upper:]]*"
1
  • If I wanted to use -regex instead of -name, what’s the correct syntax for it? Commented Feb 10, 2021 at 15:58

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.