How to remove files using find's multiple -name parameter?
When you use multiple logical operations, you need to group them by brackets as below:
find . \( -name "*.un~" -o -name "*.swo" -o -name "*.swp" \) -delete
where you have to either backslash or quote the brackets ('(' ... ')'
) to avoid parsing these special characters by the shell.
In above example I'm using -delete
instead of -exec rm -f {}
which automatically remove the file, so you don't need to worry about files with spaces, otherwise it could end up bad for you.
For more syntax examples, check man find
.
See also:
- Strange “find” behavior in Linux
- find(1) - Linux man page (OPERATORS section)