I am trying to find and delete files in current directory and subdirectories (recursively) which match different patterns and print the matching files to stdout to know which ones are deleted.For example I want to match all files starting with '&' and all files starting and ending with '$'.I've tried using:find . -type f -name '&*' -or -type f -name '$*$' -exec rm -v {} \;but rm apply only on the last match ('$*$').Thus i've tried :find . -type f -name '&*' -or -type f -name '$*$' -deleteBut this not only match only the last pattern but it doesn't output the deleted files.I know I can do this:rm -v ``find -type f -name '&*' -or -type f -name '$*$'`` but I would really like to avoid this kind of approach and do it with find command.Any tips?Thanks in advance.
Delete multiple patterns of files using one command (find)
find;regular expression;rm
You problem is that exec only applies to the second pattern, try putting parenthesis around your search conditions, to fix that:find . \( -type f -name '&*' -or -type f -name '$*$' \) -exec rm -v {} \;The thing to note is that this is not a bug, but a feature, so that you can do something like that:find -type f -name '&*' -exec mv '{}' ./backup ';' -or -type f -name '$*$' -exec rm -v '{}' ';'if you need to