diff --git a/rmdir-empty b/rmdir-empty index 774fff5..0cc0db2 100755 --- a/rmdir-empty +++ b/rmdir-empty @@ -7,9 +7,11 @@ rmdir_empty() { set -- . fi - find "$@" -depth \ - -path "." -prune -or \ - -type d -empty -exec rmdir -v {} \; + # do the first level directories first + for maxdepth_opt in "-maxdepth 1" ""; do + find "$@" -depth -mindepth 1 $maxdepth_opt \ + -type d -empty -exec rmdir -v {} \; + done } rmdir_empty "$@"