3 added 7 characters in body
source | link
function step () {
    d=$1
    d=$((d+1))
    res=$(find -mindepth $d -type d ! -empty)
    test -n "$res" && step $d || echo $((d-1))
}

find -mindepth $(step 0) -type d ! -empty | head -n 1 

Recursively step deeper and deeper into directories, as long as they contain a file (! empty! -empty). From the last step, we have to substractsubtract 1, and we can then use the result in a second find-commandfind command.

function step () {
    d=$1
    d=$((d+1))
    res=$(find -mindepth $d -type d ! -empty)
    test -n "$res" && step $d || echo $((d-1))
}

find -mindepth $(step 0) -type d ! -empty | head -n 1 

Recursively step deeper and deeper into directories, as long as they contain a file (! empty). From the last step, we have to substract 1, and can then use the result in a second find-command.

function step () {
    d=$1
    d=$((d+1))
    res=$(find -mindepth $d -type d ! -empty)
    test -n "$res" && step $d || echo $((d-1))
}

find -mindepth $(step 0) -type d ! -empty | head -n 1 

Recursively step deeper and deeper into directories, as long as they contain a file (! -empty). From the last step, we have to subtract 1, and we can then use the result in a second find command.

2 added | head -n 1, to return only one match
source | link
function step () {
    d=$1
    d=$((d+1))
    res=$(find -mindepth $d -type d ! -empty)
    test -n "$res" && step $d || echo $((d-1))
}

find -mindepth $(step 0) -type d ! -empty | head -n 1 

Recursively step deeper and deeper into directories, as long as they contain a file (! empty). From the last step, we have to substract 1, and can then use the result in a second find-command.

function step () {
    d=$1
    d=$((d+1))
    res=$(find -mindepth $d -type d ! -empty)
    test -n "$res" && step $d || echo $((d-1))
}

find -mindepth $(step 0) -type d ! -empty

Recursively step deeper and deeper into directories, as long as they contain a file (! empty). From the last step, we have to substract 1, and can then use the result in a second find-command.

function step () {
    d=$1
    d=$((d+1))
    res=$(find -mindepth $d -type d ! -empty)
    test -n "$res" && step $d || echo $((d-1))
}

find -mindepth $(step 0) -type d ! -empty | head -n 1 

Recursively step deeper and deeper into directories, as long as they contain a file (! empty). From the last step, we have to substract 1, and can then use the result in a second find-command.

1
source | link

function step () {
    d=$1
    d=$((d+1))
    res=$(find -mindepth $d -type d ! -empty)
    test -n "$res" && step $d || echo $((d-1))
}

find -mindepth $(step 0) -type d ! -empty

Recursively step deeper and deeper into directories, as long as they contain a file (! empty). From the last step, we have to substract 1, and can then use the result in a second find-command.