We can create a recursive find:
Add the following lines to a script file:
#!/bin/bash
if [ ! -f "$1"/.git ]; then
echo "$1"
find "$1" -mindepth 1 -type d -prune -exec "$0" {} \;
fi
I named the file findifnotgit but it doesn't matter.
Then make it executable
chmod u+x findifnotgit
Then run it fromwith the current dir (.)path you want to run as argument:
./findifnotgit .
(Don't forget the--> .) for current dir
or
./findifnotgit /path/to/search/
Explanation:
if [ ! -f "$1"/.git ]; then ... fiOnly run the following when there is not.gitfile inside the current folder ($1)- We need
-mindepth 1option to let find not find the folder we started with which would create an indefinite loop. - We need
-pruneso that find will not descend into directories. We will do this ourselves inside-exec. -exec "$0" {}will call the same script$0with the finds.