Why is not working? I'm trying to remove files ending by ~ and #
find . (-name "*~" -o -name "*#") -delete
Why is not working? I'm trying to remove files ending by ~ and #
find . (-name "*~" -o -name "*#") -delete
In POSIX shells (incl. bash) you need to escape the parentheses.
find . \( -name "*~" -o -name "*#" \) -delete
Here's a working example (run in an empty directory)
#!/usr/bin/bash -eu
mkdir -p a/b/c d/e f
touch a/a~ a/b/b~ 'd/e/e#' 'f/f#' 'root#' 'root~'
find . \( -name "*~" -o -name "*#" \) -delete
find .
You need to escape the paranthesis so they get interpreted by find
, not by the shell.
mkdir testme
cd testme
touch "foo~"
touch "bar#"
ls
# With parenthesis escaped
find . \( -name "*~" -o -name "*#" \) -delete
ls
cd ..
rmdir testme