I'm trying the following to recursively look for files ending in either .py
or .py.server
:
$ find -name "stub*.py(|\.server)"
However this does not work.
I've tried variations like:
$ find -name "stub*.(py|py\.server)"
They do not work either.
A simple find -name "*.py"
does work so how come this regex
does not?
Different regex types are available for the command find: findutils. emacs (which is the default option unless otherwise specified) gnu-awk.
To use regular expressions, open either the Find pane or the Replace pane and select the Use check box. When you next click Find Next, the search string is evaluated as a regular expression. When a regular expression contains characters, it usually means that the text being searched must match those characters.
GNU grep supports three regular expression syntaxes, Basic, Extended, and Perl-compatible. In its simplest form, when no regular expression type is given, grep interpret search patterns as basic regular expressions. To interpret the pattern as an extended regular expression, use the -E ( or --extended-regexp ) option.
Say:
find . \( -name "*.py" -o -name "*.py.server" \)
Saying so would result in file names matching *.py
and *.py.server
.
From man find
:
expr1 -o expr2 Or; expr2 is not evaluated if expr1 is true.
EDIT: If you want to specify a regex, use the -regex
option:
find . -type f -regex ".*\.\(py\|py\.server\)"
Find can take a regular expression pattern:
$ find . -regextype posix-extended -regex '.*[.]py([.]server)?$' -print
Options:
-regex pattern
File name matches regular expression pattern. This is a match on the whole path, not a search. For example, to match a file named
./fubar3', you can use the regular expression
.*bar.' or.*b.*3', but not
f.*r3'. The regular expressions understood by find are by default Emacs Regular Expressions, but this can be changed with the -regextype option.-print True;
print the full file name on the standard output, followed by a newline. If you are piping the output of find into another program and there is the faintest possibility that the files which you are searching for might contain a newline, then you should seriously consider using the -print0 option instead of -print. See the UNUSUAL FILENAMES section for information about how unusual characters in filenames are handled.
-regextype type
Changes the regular expression syntax understood by -regex and -iregex tests which occur later on the command line. Currently-implemented types are emacs (this is the default), posix-awk, posix- basic, posix-egrep and posix-extended.
A clearer description or the options. Don't forgot all the information can be found by reading man find
or info find
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With