Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save justinfrench/18780 to your computer and use it in GitHub Desktop.
Save justinfrench/18780 to your computer and use it in GitHub Desktop.
undefined
# Recursively add a .gitignore file to all directories
# in the working directory which are empty and don't
# start with a dot. Helpful for tracking empty dirs
# in a git repository.
for i in $(find . -type d -regex ``./[^.].*'' -empty); do touch $i"/.gitignore"; done;
@geirha
Copy link

geirha commented May 8, 2015

This does not work recursively. It will only work for the first level of directories, assuming the shell doesn't modify the regex first, which it might since the regex is unquoted.

Also, -regex is a GNU-ism, and is also an overkill here since the equivalent glob is actually simpler and shorter.

find . -type d ! -name ".*" -empty -exec touch {}/.gitignore \;

This is more portable. -empty is not standard, but both GNU and BSD find has it, so it will work on most systems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment