Skip to main content
added 26 characters in body
Source Link
pLumo
  • 23.2k
  • 2
  • 43
  • 70

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 ... fi Only run the following when there is not .git file inside the current folder ($1)
  • We need -mindepth 1 option to let find not find the folder we started with which would create an indefinite loop.
  • We need -prune so that find will not descend into directories. We will do this ourselves inside -exec.
  • -exec "$0" {} will call the same script $0 with the finds.

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 from the current dir (.):

./findifnotgit .

(Don't forget the .)


Explanation:

  • if [ ! -f "$1"/.git ]; then ... fi Only run the following when there is not .git file inside the current folder ($1)
  • We need -mindepth 1 option to let find not find the folder we started with which would create an indefinite loop.
  • We need -prune so that find will not descend into directories. We will do this ourselves inside -exec.
  • -exec "$0" {} will call the same script $0 with the finds.

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 with the path you want to run as argument:

./findifnotgit .

--> . for current dir

or

./findifnotgit /path/to/search/

Explanation:

  • if [ ! -f "$1"/.git ]; then ... fi Only run the following when there is not .git file inside the current folder ($1)
  • We need -mindepth 1 option to let find not find the folder we started with which would create an indefinite loop.
  • We need -prune so that find will not descend into directories. We will do this ourselves inside -exec.
  • -exec "$0" {} will call the same script $0 with the finds.
added 26 characters in body
Source Link
pLumo
  • 23.2k
  • 2
  • 43
  • 70

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 from the current dir (.):

./findifnotgit .

(Don't forget the .)


Explanation:

  • if [ ! -f "$1"/.git ]; then ... fi Only run the following when there is not .git file inside the current folder ($1)
  • We need -mindepth 1 option to let find not find the folder we started with which would create an indefinite loop.
  • We need -prune so that find will not descend into directories. We will do this ourselves inside -exec.
  • -exec "$0" {} will call the same script $0 with the finds.

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 from the current dir (.):

./findifnotgit .

Explanation:

  • if [ ! -f "$1"/.git ]; then ... fi Only run the following when there is not .git file inside the current folder ($1)
  • We need -mindepth 1 option to let find not find the folder we started with which would create an indefinite loop.
  • We need -prune so that find will not descend into directories. We will do this ourselves inside -exec.
  • -exec "$0" {} will call the same script $0 with the finds.

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 from the current dir (.):

./findifnotgit .

(Don't forget the .)


Explanation:

  • if [ ! -f "$1"/.git ]; then ... fi Only run the following when there is not .git file inside the current folder ($1)
  • We need -mindepth 1 option to let find not find the folder we started with which would create an indefinite loop.
  • We need -prune so that find will not descend into directories. We will do this ourselves inside -exec.
  • -exec "$0" {} will call the same script $0 with the finds.
deleted 1 character in body
Source Link
pLumo
  • 23.2k
  • 2
  • 43
  • 70

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 from the current dir (.):

./findifnotgit .

Explanation:

  • if [ ! -df "$1"/.git ]; then ... fi Only run the following when there is not .git folder belowfile inside the current folder ($1)
  • We need -mindepth 1 option to let find not find the folder we started with which would create an indefinite loop.
  • We need -prune so that find will not descend into directories. We will do this ourselves inside -exec.
  • -exec "$0" {} will call the same script $0 with the finds.

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 from the current dir (.):

./findifnotgit .

Explanation:

  • if [ ! -d "$1"/.git ]; then ... fi Only run the following when there is not .git folder below the current folder ($1)
  • We need -mindepth 1 option to let find not find the folder we started with which would create an indefinite loop.
  • We need -prune so that find will not descend into directories. We will do this ourselves inside -exec.
  • -exec "$0" {} will call the same script $0 with the finds.

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 from the current dir (.):

./findifnotgit .

Explanation:

  • if [ ! -f "$1"/.git ]; then ... fi Only run the following when there is not .git file inside the current folder ($1)
  • We need -mindepth 1 option to let find not find the folder we started with which would create an indefinite loop.
  • We need -prune so that find will not descend into directories. We will do this ourselves inside -exec.
  • -exec "$0" {} will call the same script $0 with the finds.
deleted 8 characters in body
Source Link
pLumo
  • 23.2k
  • 2
  • 43
  • 70
Loading
Source Link
pLumo
  • 23.2k
  • 2
  • 43
  • 70
Loading