Use multiple conditions in find regex in shell

findregexshell

EDITED:
I need to use -E for extended regex.

I have a folder with this files (just an example):
directory structure

I'm trying to find all files that:

  1. Start and end with #. (e.g #hi.h#)
  2. End with ~. (e.g file.txt~)

I can find 1 condition files or 2 condition files, but i can't combine both in one regex.

$ find . -regex "./.*~"
./lld~

$ find . -regex "./#.*#"
./#x2#
./#x#

But this command is not working:

$ find . -regex "./(.*~$)|(#.*#)"

What am I doing wrong? how I can combine these regexes?

Best Answer

find . -regex "\./#.*#\|\./.*~"

Does this work for you?

Related Question