Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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;
@alkos333

This comment has been minimized.

Show comment
Hide comment
@alkos333

alkos333 Jan 26, 2012

Does the same thing, but w/o a for loop: https://gist.github.com/1685784

Does the same thing, but w/o a for loop: https://gist.github.com/1685784

@dalers

This comment has been minimized.

Show comment
Hide comment
@dalers

dalers Jan 23, 2013

Thanks for posting, much easier than manually going through directories or creating a hardcoded script that's wrong next Yii release. I must be missing something regarding the recursion though. Is it actually iterative?

dalers commented Jan 23, 2013

Thanks for posting, much easier than manually going through directories or creating a hardcoded script that's wrong next Yii release. I must be missing something regarding the recursion though. Is it actually iterative?

@chan-grammer

This comment has been minimized.

Show comment
Hide comment
@chan-grammer

chan-grammer May 7, 2015

just a little question what does `` mean in the regex?

just a little question what does `` mean in the regex?

@geirha

This comment has been minimized.

Show comment
Hide comment
@geirha

geirha 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.

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