Skip to main content
fixed script
Source Link
RobotJohnny
  • 1.1k
  • 8
  • 19

Bit of a dirty script, but this will find all directories that don't contain a .git file in them:

#!/bin/bash

# find dirs that contain *.git files and store in array
exclude_dirs=($(find . -type f -nameiname ".git" | cut -d "/"xargs -f 2 | sorti |dirname uniq{}))

# set up the base command
command="find . -type d"

# loop over each element in array by index
for i in $(seq 0 $(expr ${#exclude_dirs[@]} - 1)); do
    command="${command} -not -path ./${exclude_dirs[$i]}"
done

# run the find
eval ${command}

###edit: fixed syntax errors and updated *.git to .git

###edit2: yep that was wrong, my apologies. Edited so it actually works now.

Bit of a dirty script, but this will find all directories that don't contain a .git file in them:

#!/bin/bash

# find dirs that contain .git files and store in array
exclude_dirs=($(find . -type f -name ".git" | cut -d "/" -f 2 | sort | uniq))

# set up the base command
command="find . -type d"

# loop over each element in array by index
for i in $(seq 0 $(expr ${#exclude_dirs[@]} - 1)); do
    command="${command} -not -path ./${exclude_dirs[$i]}"
done

# run the find
eval ${command}

###edit: fixed syntax errors and updated *.git to .git

Bit of a dirty script, but this will find all directories that don't contain a .git file in them:

#!/bin/bash

# find dirs that contain *.git files and store in array
exclude_dirs=($(find . -type f -iname ".git" | xargs -i dirname {}))

# set up the base command
command="find . -type d"

# loop over each element in array by index
for i in $(seq 0 $(expr ${#exclude_dirs[@]} - 1)); do
    command="${command} -not -path ${exclude_dirs[$i]}"
done

# run the find
eval ${command}

###edit: fixed syntax errors and updated *.git to .git

###edit2: yep that was wrong, my apologies. Edited so it actually works now.

syntax error fix
Source Link
RobotJohnny
  • 1.1k
  • 8
  • 19

Bit of a dirty script, but this will find all directories that don't contain a *.git file in them:

#!/bin/bash

# find dirs that contain *.git files and store in array
exclude_dirs=($(find . -type f -inamename "*".git" | cut -d "/" -f 2 | sort | uniq))

# set up the base command
command="find . -type d"

# loop over each element in array by index
for i in $(seq 0 $(expr ${#exclude_files[@]#exclude_dirs[@]} - 1)); do
    command="${command} -not -path "$./${exclude_files[$i]exclude_dirs[$i]}"
done

# run the find
eval ${command}

###edit: fixed syntax errors and updated *.git to .git

Bit of a dirty script, but this will find all directories that don't contain a *.git file in them:

#!/bin/bash

# find dirs that contain *.git files and store in array
exclude_dirs=($(find . -type f -iname "*.git" | cut -d "/" -f 2 | sort | uniq))

# set up the base command
command="find . -type d"

# loop over each element in array by index
for i in $(seq 0 $(expr ${#exclude_files[@]} - 1)); do
    command="${command} -not -path "${exclude_files[$i]}"
done

# run the find
eval ${command}

Bit of a dirty script, but this will find all directories that don't contain a .git file in them:

#!/bin/bash

# find dirs that contain .git files and store in array
exclude_dirs=($(find . -type f -name ".git" | cut -d "/" -f 2 | sort | uniq))

# set up the base command
command="find . -type d"

# loop over each element in array by index
for i in $(seq 0 $(expr ${#exclude_dirs[@]} - 1)); do
    command="${command} -not -path ./${exclude_dirs[$i]}"
done

# run the find
eval ${command}

###edit: fixed syntax errors and updated *.git to .git

Source Link
RobotJohnny
  • 1.1k
  • 8
  • 19

Bit of a dirty script, but this will find all directories that don't contain a *.git file in them:

#!/bin/bash

# find dirs that contain *.git files and store in array
exclude_dirs=($(find . -type f -iname "*.git" | cut -d "/" -f 2 | sort | uniq))

# set up the base command
command="find . -type d"

# loop over each element in array by index
for i in $(seq 0 $(expr ${#exclude_files[@]} - 1)); do
    command="${command} -not -path "${exclude_files[$i]}"
done

# run the find
eval ${command}