Skip to content

Instantly share code, notes, and snippets.

@xaptronic
Created November 7, 2011 13:57
Show Gist options
  • Save xaptronic/1345071 to your computer and use it in GitHub Desktop.
Save xaptronic/1345071 to your computer and use it in GitHub Desktop.
Find empty directories and do something with them.
function do_if_dir_empty {
[ "$(ls -A $1/)" ] || eval "$2"
}
find . -type d -not \( -wholename "*/.git*" -or -wholename "*/.svn*" \) -print | while read F; do do_if_dir_empty $F "$1"; done
# Usage: find_empty_dirs_and_do 'echo $1 is an empty dir'
# Ex: find_empty_dirs_and_do 'cp /path/to/gitignore $1/.gitignore' # now this directory will be tracked by git
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment