Skip to main content
improve title & add bold formatting
Source Link

Recursively create empty filefiles in all empty 'leaf' sub-directories

I have created the directory structure for my Maven project.

$ tree -a -I .git . ├── .gitignore ├── README.md ├── pom.xml └── src ├── main │   ├── java │   └── resources └── test ├── java └── resources 7 directories, 2 files 

Now I'd like to persist the structure to .git, which requires creating dummy files in sub-directories. How can I (recursively) add empty .gitkeep files to all empty sub-directories?


Following questions already discuss (recursive) creation of empty files in sub-directories, but I'd like the files to be created only in leaf directoriesfiles to be created only in leaf directories and not in any intermediate directories and not in any intermediate directories

Recursively create empty file in empty sub-directories

I have created the directory structure for my Maven project.

$ tree -a -I .git . ├── .gitignore ├── README.md ├── pom.xml └── src ├── main │   ├── java │   └── resources └── test ├── java └── resources 7 directories, 2 files 

Now I'd like to persist the structure to .git, which requires creating dummy files in sub-directories. How can I (recursively) add empty .gitkeep files to all empty sub-directories?


Following questions already discuss (recursive) creation of empty files in sub-directories, but I'd like the files to be created only in leaf directories and not in any intermediate directories

Recursively create empty files in all empty 'leaf' sub-directories

I have created the directory structure for my Maven project.

$ tree -a -I .git . ├── .gitignore ├── README.md ├── pom.xml └── src ├── main │   ├── java │   └── resources └── test ├── java └── resources 7 directories, 2 files 

Now I'd like to persist the structure to .git, which requires creating dummy files in sub-directories. How can I (recursively) add empty .gitkeep files to all empty sub-directories?


Following questions already discuss (recursive) creation of empty files in sub-directories, but I'd like the files to be created only in leaf directories and not in any intermediate directories

Source Link

Recursively create empty file in empty sub-directories

I have created the directory structure for my Maven project.

$ tree -a -I .git . ├── .gitignore ├── README.md ├── pom.xml └── src ├── main │   ├── java │   └── resources └── test ├── java └── resources 7 directories, 2 files 

Now I'd like to persist the structure to .git, which requires creating dummy files in sub-directories. How can I (recursively) add empty .gitkeep files to all empty sub-directories?


Following questions already discuss (recursive) creation of empty files in sub-directories, but I'd like the files to be created only in leaf directories and not in any intermediate directories