I want to maintain a folder structure that contains empty folders when I add a project to Git. As everyone knows, Git doesn't track empty folders. So you need to add some kind of placeholder inside of an empty folder.

So far I have managed to find out recursively empty folders with this command:

find ./* -type d -empty

How do I continue? So after a command every empty folder contains a file called "empty"?

3 Answers
3

That one above only added empty on "." (current) folder. I'm running this on Linux if that helps...? I ran across to a blog post which claimed that there are some differences between MacOSX and Linux. Here: aplawrence.com/Unixart/find_execdir.html
–
hemppaJun 11 '13 at 20:30

Are you running the command exactly as Ignacio wrote? I think he means for you to run find . -type d -empty -execdir touch empty \;
–
evilsoupJun 11 '13 at 21:01

thanks for clarification. I was doing it wrong, but still it won't add that empty file to all folders... actually it adds it only in "."-folder and "./level1/"-folder, which is btw not empty. This is strange, find . -type d -empty displays all correct folders though..
–
hemppaJun 11 '13 at 21:23

I've just tested it, and I'm getting the same behaviour... bizarrely, it seems to be touching the 'empty' files in the directory one above the empty directories.
–
evilsoupJun 11 '13 at 21:56

Globstar means that ** expands into 'every file in this directory, recursively'; **/ means that it will only expand to directories, rather than regular files (since filenames can't contain forward-slashes).

Nullglob means that globs which don't match anything expand to a nullbyte. The test checks if this happens (which would mean that there's nothing in the directory); if the test evaluates to true (which means there's nothing in the directory), then it touches empty in the directory.