Skip to main content
Layout the debugging version a little more (?) clearly
Source Link
Chris Davies
  • 128.2k
  • 16
  • 179
  • 324

Traverse the hierarchy of directories, and in each one prune the tree if the flag file (pattern) is found, but otherwise search for the wanted files (*proj*.tgz)

find /top/dir -type d -exec sh -c 'z=$(find "$@" -maxdepth 1 -type f -name "pattern" -print -quit); [ -n "$z" ]' _ {} \; -prune -o -type f -name '*proj*.tgz' -print

I ended up writing a more complex version of this that allowed me to see what was going on. Obviously I had to change /top/dir, pattern, and *proj*.tgz for items that were relevant locally.) I'll include it here for posterity

find /top/dir -type d \
    -exec shbash -c '
        echo "Considering $*";
        z=$(find "$@" -maxdepth 1 -type f -printf "| %p\n" -name "pattern" -printf "Found flag file\n" -quit);
        [[[ -n "$z" ]]] && echo "$z";
        echo[[ "$z" | grep -F=~ "Found flag file" >/dev/null]] || ({ echo "No flag found"; exit 11; )}
    ' _ {} \; \
    -printf "Pruning tree\n" -prune \
    -o \
    -type f -name '*proj*.tgz' -print

The real solution requires the non-POSIX find -maxdepth. The debugging version also requires non-POSIX find -printf. There is an alternate approach for implementing -maxdepth that satisfies POSIX, but I haven't used it here; the code is opaque enough as it is.

Traverse the hierarchy of directories, and in each one prune the tree if the flag file (pattern) is found, but otherwise search for the wanted files (*proj*.tgz)

find /top/dir -type d -exec sh -c 'z=$(find "$@" -maxdepth 1 -type f -name "pattern" -print -quit); [ -n "$z" ]' _ {} \; -prune -o -type f -name '*proj*.tgz' -print

I ended up writing a more complex version of this that allowed me to see what was going on. Obviously I had to change /top/dir, pattern, and *proj*.tgz for items that were relevant locally.) I'll include it here for posterity

find /top/dir -type d \
    -exec sh -c '
        echo "Considering $*";
        z=$(find "$@" -maxdepth 1 -type f -printf "| %p\n" -name "pattern" -printf "Found flag file\n" -quit);
        [ -n "$z" ] && echo "$z";
        echo "$z" | grep -F "Found flag file" >/dev/null || ( echo "No flag found"; exit 1 )
    ' _ {} \; \
    -printf "Pruning tree\n" -prune \
    -o \
    -type f -name '*proj*.tgz' -print

The real solution requires the non-POSIX find -maxdepth. The debugging version also requires non-POSIX find -printf. There is an alternate approach for implementing -maxdepth that satisfies POSIX, but I haven't used it here; the code is opaque enough as it is.

Traverse the hierarchy of directories, and in each one prune the tree if the flag file (pattern) is found, but otherwise search for the wanted files (*proj*.tgz)

find /top/dir -type d -exec sh -c 'z=$(find "$@" -maxdepth 1 -type f -name "pattern" -print -quit); [ -n "$z" ]' _ {} \; -prune -o -type f -name '*proj*.tgz' -print

I ended up writing a more complex version of this that allowed me to see what was going on. Obviously I had to change /top/dir, pattern, and *proj*.tgz for items that were relevant locally.) I'll include it here for posterity

find /top/dir -type d \
    -exec bash -c '
        echo "Considering $*";
        z=$(find "$@" -maxdepth 1 -type f -printf "| %p\n" -name "pattern" -printf "Found flag file\n" -quit);
        [[ -n "$z" ]] && echo "$z";
        [[ "$z" =~ "Found flag file" ]] || { echo "No flag found"; exit 1; }
    ' _ {} \; \
    -printf "Pruning tree\n" -prune \
    -o \
    -type f -name '*proj*.tgz' -print

The real solution requires the non-POSIX find -maxdepth. The debugging version also requires non-POSIX find -printf. There is an alternate approach for implementing -maxdepth that satisfies POSIX, but I haven't used it here; the code is opaque enough as it is.

Layout the debugging version a little more (?) clearly
Source Link
Chris Davies
  • 128.2k
  • 16
  • 179
  • 324

Traverse the hierarchy of directories, and in each one prune the tree if the flag file (pattern) is found, but otherwise search for the wanted files (*proj*.tgz)

find /top/dir -type d -exec sh -c 'z=$(find "$@" -maxdepth 1 -type f -name "pattern" -printf "Found flag\n"print -quit); [ -n "$z" ]' _ {} \; -prune -o -type f -name '*proj*.tgz' -print

I ended up writing a more complex version of this that allowed me to see what was going on. Obviously I had to change /top/dir, pattern, and *proj*.tgz for items that were relevant locally.) I'll include it here for posterity

find /top/dir -type d \
    -exec sh -c 'echo'
        echo "Considering $*";
        z=$(find "$@" -maxdepth 1 -type f -printf "| %p\n" -name "pattern" -printf "Found flag file\n" -quit); 
 [[       [ -n "$z" ]]] && echo "$z"; 
 [       echo "$z" =~| grep -F "Found flag file" ]>/dev/null || {( echo "No flag found"; exit 1;1 })
    ' _ {} \; \
    -printf "Pruning tree\n" -prune \
    -o \
    -type f -name '*proj*.tgz' -print

The real solution requires the non-POSIX find -maxdepth. The debugging version also requires non-POSIX find -printf. There is an alternate approach for implementing -maxdepth that satisfies POSIX, but I haven't used it here; the code is opaque enough as it is.

Traverse the hierarchy of directories, and in each one prune the tree if the flag file (pattern) is found, but otherwise search for the wanted files (*proj*.tgz)

find /top/dir -type d -exec sh -c 'z=$(find "$@" -maxdepth 1 -type f -name "pattern" -printf "Found flag\n" -quit); [ -n "$z" ]' _ {} \; -prune -o -type f -name '*proj*.tgz' -print

I ended up writing a more complex version of this that allowed me to see what was going on. Obviously I had to change /top/dir, pattern, and *proj*.tgz for items that were relevant locally.) I'll include it here for posterity

find /top/dir -type d -exec sh -c 'echo "Considering $*"; z=$(find "$@" -maxdepth 1 -type f -printf "| %p\n" -name "pattern" -printf "Found flag file\n" -quit); [[ -n "$z" ]] && echo "$z"; [ "$z" =~ "Found flag file" ] || { echo "No flag found"; exit 1; }' _ {} \; -printf "Pruning tree\n" -prune -o -type f -name '*proj*.tgz' -print

The solution requires the non-POSIX find -maxdepth. There is an alternate approach for implementing -maxdepth that satisfies POSIX, but I haven't used it here; the code is opaque enough as it is.

Traverse the hierarchy of directories, and in each one prune the tree if the flag file (pattern) is found, but otherwise search for the wanted files (*proj*.tgz)

find /top/dir -type d -exec sh -c 'z=$(find "$@" -maxdepth 1 -type f -name "pattern" -print -quit); [ -n "$z" ]' _ {} \; -prune -o -type f -name '*proj*.tgz' -print

I ended up writing a more complex version of this that allowed me to see what was going on. Obviously I had to change /top/dir, pattern, and *proj*.tgz for items that were relevant locally.) I'll include it here for posterity

find /top/dir -type d \
    -exec sh -c '
        echo "Considering $*";
        z=$(find "$@" -maxdepth 1 -type f -printf "| %p\n" -name "pattern" -printf "Found flag file\n" -quit); 
        [ -n "$z" ] && echo "$z"; 
        echo "$z" | grep -F "Found flag file" >/dev/null || ( echo "No flag found"; exit 1 )
    ' _ {} \; \
    -printf "Pruning tree\n" -prune \
    -o \
    -type f -name '*proj*.tgz' -print

The real solution requires the non-POSIX find -maxdepth. The debugging version also requires non-POSIX find -printf. There is an alternate approach for implementing -maxdepth that satisfies POSIX, but I haven't used it here; the code is opaque enough as it is.

Source Link
Chris Davies
  • 128.2k
  • 16
  • 179
  • 324

Traverse the hierarchy of directories, and in each one prune the tree if the flag file (pattern) is found, but otherwise search for the wanted files (*proj*.tgz)

find /top/dir -type d -exec sh -c 'z=$(find "$@" -maxdepth 1 -type f -name "pattern" -printf "Found flag\n" -quit); [ -n "$z" ]' _ {} \; -prune -o -type f -name '*proj*.tgz' -print

I ended up writing a more complex version of this that allowed me to see what was going on. Obviously I had to change /top/dir, pattern, and *proj*.tgz for items that were relevant locally.) I'll include it here for posterity

find /top/dir -type d -exec sh -c 'echo "Considering $*"; z=$(find "$@" -maxdepth 1 -type f -printf "| %p\n" -name "pattern" -printf "Found flag file\n" -quit); [[ -n "$z" ]] && echo "$z"; [ "$z" =~ "Found flag file" ] || { echo "No flag found"; exit 1; }' _ {} \; -printf "Pruning tree\n" -prune -o -type f -name '*proj*.tgz' -print

The solution requires the non-POSIX find -maxdepth. There is an alternate approach for implementing -maxdepth that satisfies POSIX, but I haven't used it here; the code is opaque enough as it is.