I need to use -E
for extended regex.
Invoke find . -regextype help
to learn available options. GNU find
in my Debian supports few. This works:
find . -regextype posix-extended -regex '\./(.*~$|#.*#)'
Note I have debugged and simplified the regex a little (\./.*~$|\./#.*#
would also work). Other options that work for me in this particular case: posix-egrep
, egrep
, posix-awk
, awk
, gnu-awk
.
This command:
find . -regex '\./#.*#\|\./.*~'
where |
is escaped works for me. Credits to the other answer. Proper escaping of (
and )
makes the following work as well:
find . -regex '\./\(.*~$\|#.*#\)'
without relying on extended regular expressions.
You don't have to compact the two expressions into one. If these work:
find . -regex '\./.*~'
find . -regex '\./#.*#'
then you can get files matching one regex or the other this way:
find . -regex '\./.*~' -o -regex '\./#.*#'
Be warned: Why does find
in Linux skip expected results when -o
is used? If you want to add more tests/actions before and/or after then you don't want this:
find . -test1 -test2 -regex '\./.*~' -o -regex '\./#.*#' -test3 …
but this:
find . -test1 -test2 '(' -regex '\./.*~' -o -regex '\./#.*#' ')' -test3 …