Recursively create empty file in empty sub-directories

Clash Royale CLAN TAG#URR8PPP
up vote
2
down vote
favorite
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
- Creating empty files in all subfolders
- Recursively add a file to all sub-directories
bash command-line
add a comment |Â
up vote
2
down vote
favorite
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
- Creating empty files in all subfolders
- Recursively add a file to all sub-directories
bash command-line
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
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
- Creating empty files in all subfolders
- Recursively add a file to all sub-directories
bash command-line
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
- Creating empty files in all subfolders
- Recursively add a file to all sub-directories
bash command-line
bash command-line
asked Aug 16 at 18:42
y2k-shubham
1616
1616
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
5
down vote
accepted
From Ryan Armstrong's blog, here's how you do it
find . -type d -empty -not -path "./.git/*" -exec touch /.gitkeep ;
find . -type d(recursively) looks for directories under current path-emptyfilters out directories that already contain something-not -path "./.git/*"ensures no files are created inside.gitdirectory-exec touch /.gitkeep ;creates empty.gitkeepfile in each directory matching above criteria
The resulting structure looks like
$ tree -a -I .git
.
âÂÂâÂÂâ .gitignore
âÂÂâÂÂâ README.md
âÂÂâÂÂâ pom.xml
âÂÂâÂÂâ src
âÂÂâÂÂâ main
âÂÂààâÂÂâÂÂâ java
âÂÂààâÂÂààâÂÂâÂÂâ .gitkeep
âÂÂààâÂÂâÂÂâ resources
âÂÂààâÂÂâÂÂâ .gitkeep
âÂÂâÂÂâ test
âÂÂâÂÂâ java
âÂÂààâÂÂâÂÂâ .gitkeep
âÂÂâÂÂâ resources
âÂÂâÂÂâ .gitkeep
7 directories, 7 files
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
5
down vote
accepted
From Ryan Armstrong's blog, here's how you do it
find . -type d -empty -not -path "./.git/*" -exec touch /.gitkeep ;
find . -type d(recursively) looks for directories under current path-emptyfilters out directories that already contain something-not -path "./.git/*"ensures no files are created inside.gitdirectory-exec touch /.gitkeep ;creates empty.gitkeepfile in each directory matching above criteria
The resulting structure looks like
$ tree -a -I .git
.
âÂÂâÂÂâ .gitignore
âÂÂâÂÂâ README.md
âÂÂâÂÂâ pom.xml
âÂÂâÂÂâ src
âÂÂâÂÂâ main
âÂÂààâÂÂâÂÂâ java
âÂÂààâÂÂààâÂÂâÂÂâ .gitkeep
âÂÂààâÂÂâÂÂâ resources
âÂÂààâÂÂâÂÂâ .gitkeep
âÂÂâÂÂâ test
âÂÂâÂÂâ java
âÂÂààâÂÂâÂÂâ .gitkeep
âÂÂâÂÂâ resources
âÂÂâÂÂâ .gitkeep
7 directories, 7 files
add a comment |Â
up vote
5
down vote
accepted
From Ryan Armstrong's blog, here's how you do it
find . -type d -empty -not -path "./.git/*" -exec touch /.gitkeep ;
find . -type d(recursively) looks for directories under current path-emptyfilters out directories that already contain something-not -path "./.git/*"ensures no files are created inside.gitdirectory-exec touch /.gitkeep ;creates empty.gitkeepfile in each directory matching above criteria
The resulting structure looks like
$ tree -a -I .git
.
âÂÂâÂÂâ .gitignore
âÂÂâÂÂâ README.md
âÂÂâÂÂâ pom.xml
âÂÂâÂÂâ src
âÂÂâÂÂâ main
âÂÂààâÂÂâÂÂâ java
âÂÂààâÂÂààâÂÂâÂÂâ .gitkeep
âÂÂààâÂÂâÂÂâ resources
âÂÂààâÂÂâÂÂâ .gitkeep
âÂÂâÂÂâ test
âÂÂâÂÂâ java
âÂÂààâÂÂâÂÂâ .gitkeep
âÂÂâÂÂâ resources
âÂÂâÂÂâ .gitkeep
7 directories, 7 files
add a comment |Â
up vote
5
down vote
accepted
up vote
5
down vote
accepted
From Ryan Armstrong's blog, here's how you do it
find . -type d -empty -not -path "./.git/*" -exec touch /.gitkeep ;
find . -type d(recursively) looks for directories under current path-emptyfilters out directories that already contain something-not -path "./.git/*"ensures no files are created inside.gitdirectory-exec touch /.gitkeep ;creates empty.gitkeepfile in each directory matching above criteria
The resulting structure looks like
$ tree -a -I .git
.
âÂÂâÂÂâ .gitignore
âÂÂâÂÂâ README.md
âÂÂâÂÂâ pom.xml
âÂÂâÂÂâ src
âÂÂâÂÂâ main
âÂÂààâÂÂâÂÂâ java
âÂÂààâÂÂààâÂÂâÂÂâ .gitkeep
âÂÂààâÂÂâÂÂâ resources
âÂÂààâÂÂâÂÂâ .gitkeep
âÂÂâÂÂâ test
âÂÂâÂÂâ java
âÂÂààâÂÂâÂÂâ .gitkeep
âÂÂâÂÂâ resources
âÂÂâÂÂâ .gitkeep
7 directories, 7 files
From Ryan Armstrong's blog, here's how you do it
find . -type d -empty -not -path "./.git/*" -exec touch /.gitkeep ;
find . -type d(recursively) looks for directories under current path-emptyfilters out directories that already contain something-not -path "./.git/*"ensures no files are created inside.gitdirectory-exec touch /.gitkeep ;creates empty.gitkeepfile in each directory matching above criteria
The resulting structure looks like
$ tree -a -I .git
.
âÂÂâÂÂâ .gitignore
âÂÂâÂÂâ README.md
âÂÂâÂÂâ pom.xml
âÂÂâÂÂâ src
âÂÂâÂÂâ main
âÂÂààâÂÂâÂÂâ java
âÂÂààâÂÂààâÂÂâÂÂâ .gitkeep
âÂÂààâÂÂâÂÂâ resources
âÂÂààâÂÂâÂÂâ .gitkeep
âÂÂâÂÂâ test
âÂÂâÂÂâ java
âÂÂààâÂÂâÂÂâ .gitkeep
âÂÂâÂÂâ resources
âÂÂâÂÂâ .gitkeep
7 directories, 7 files
edited Aug 16 at 18:43
ilkkachu
51.2k678141
51.2k678141
answered Aug 16 at 18:42
y2k-shubham
1616
1616
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f463044%2frecursively-create-empty-file-in-empty-sub-directories%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password