This should work:
find ./application -depth -mindepth 1 -type d \ -regextype posix-extended ! -regex ".*\/(config|logs).*" | \ -exec rm -fr {} \;
Or with xargs , if you donβt have folder names with new characters in them, you can write:
find ./application -depth -mindepth 1 -type d \ -regextype posix-extended ! -regex ".*\/(config|logs).*" | \ xargs -t -I {} rm -fr {}
Or with xargs , if you have folder names with new characters in them, you can use:
find ./application -depth -mindepth 1 -type d \ -regextype posix-extended ! -regex ".*\/(config|logs).*" -print0 | \ xargs -0 -t -I {} rm -fr {}
find finds all the directories below ./application , excluding those that have /config and /logs , and prints them starting at the lowestxargs directory removal is performed
source share