0

This question already has an answer here:

I want to find all files (in current and all subdirectory) which end in'~' or 'pyc'. To do so I have tried the following find pattern:

find . -name '*{~,pyc}'
find . -name '{*~,*.pyc}'

but neither list any of the files present in the diectory. Why do these patterns not work? How to do it right?

When using ls instead of find (without the quotation mark) I get the expected result (except that ls only shows the current directory and not all the subdirectories).

marked as duplicate by jasonwryan, Chris Down, vonbrand, daisy, rahmu Apr 6 '13 at 12:20

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 2
    Why are you asking the same question again? – Stéphane Chazelas Apr 6 '13 at 7:50
  • It is a different question. I wanted to use a more compact expression to do a similar task. – Alex Apr 6 '13 at 7:54
4

It would be much easier with regular expression if you have the GNU find,

find . -regextype posix-egrep -regex '.*(~|pyc)$'

P.S I guess you're using shell expansion with find? If so, that's not possible, use find . -name '*.pyc' -o -name '*~' instead.

5
find . -type f \( -name "*~" -o -name "*pyc" \)

This will return all files (-type f) that end with either ~ or (-o) pyc.

3

If it's compactness you're after, with zsh:

printf '%s\n' **/*(~|pyc)(.D)

(D for dotfiles as well, . for regular files only)

If you wanted to use shell brace expansion, you'd have to do things like:

eval 'find . -type f ! \(' '! -name \*'{~,pyc} '\)'

Which the shell expands to:

eval 'find . -type f ! \(' '! -name \*~' '! -name \*pyc' '\)'

Which is then asking the shell to evaluate this command line:

find . -type f ! \( ! -name \*~ ! -name \*pyc \)

Not the answer you're looking for? Browse other questions tagged or ask your own question.