3

The first example without pipe return empty.

find /tmp/txz/httperf/httperf-20210403git/ -regextype posix-egrep -regex [A-Z][A-Z]$

The second return what I want, all files with capitalized letters, why the find command return nothing?

find /tmp/txz/httperf/httperf-20210403git/ |egrep [A-Z][A-Z]$ 
/tmp/txz/httperf/httperf-20210403git/.git/refs/remotes/origin/HEAD
/tmp/txz/httperf/httperf-20210403git/.git/logs/refs/remotes/origin/HEAD
/tmp/txz/httperf/httperf-20210403git/.git/logs/HEAD
/tmp/txz/httperf/httperf-20210403git/.git/HEAD
/tmp/txz/httperf/httperf-20210403git/NEWS
/tmp/txz/httperf/httperf-20210403git/COPYRIGHT
/tmp/txz/httperf/httperf-20210403git/AUTHORS
/tmp/txz/httperf/httperf-20210403git/TODO
/tmp/txz/httperf/httperf-20210403git/src/lib/README

I have tried also posix-extended and posix-basic for regex-type, but return empty.

1
  • 2
    You should always quote the argument to -regex and -name, otherwise the shell might expand them before find sees them.
    – Barmar
    Apr 4, 2021 at 14:45

1 Answer 1

6

As POSIX find does not specify -regex, I assume GNU find.

Test: -regex expr
Test: -iregex expr
True if the entire file name matches regular expression expr. This is a match on the whole path, not a search. […]

(source, emphasis mine)

You should use -regex '.*[A-Z][A-Z]'. Note the expression is single-quoted to prevent expansion by the shell.

1
  • or something like -regex '.*/[A-Z]+$', to match .../HEAD, but not .../fooBAR
    – ilkkachu
    Apr 3, 2021 at 21:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .