Using find, sort and xargs from GNU CoreUtils:
find . -depth -name '*.exe' -o -name '*.bat' -printf '%h\0' |
sort --zero-terminated --uniq |
xargs --null -- echo rm -r --
- GNU
find
supports -printf '%h\0'
which will print the leading directory name followed by a null
character.
sort --zero-terminated --uniq
sorts the null
delimited list stream while removing duplicates.
xargs --null --
transforms the null
delimited entries onto arguments to the command.
echo rm -r --
executed by xargs
to delete recursively. The echo
turns this into a dummy to check the output. Remove the echo
if the result matches your expectations.