Skip to content

Instantly share code, notes, and snippets.

@igorvolnyi
Created August 25, 2021 10:17
Show Gist options
  • Save igorvolnyi/34eac6b96fc26c61917599edc8bb0926 to your computer and use it in GitHub Desktop.
Save igorvolnyi/34eac6b96fc26c61917599edc8bb0926 to your computer and use it in GitHub Desktop.
Remove all empty directories in current directory (bash, zsh)
# Say you have a directory containing thousands of subdirectories. And you want to remove all empty ones.
# NOTE: It is not recursive.
for d in *; do [[ -d "${d}" ]] && [[ `ls "${d}" | wc -l` = "0" ]] && rmdir -v "${d}"; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment