Skip to main content
deleted 142 characters in body
Source Link
bu5hman
  • 4.9k
  • 2
  • 16
  • 29

Walking up the directory path

f=/home/bu5hman/test; file=${f##*/}; base=${f%/*}
while [ ! -z $base ]; do
    find $base -maxdepth 1 -name $file
    base=${base%/*}
done

By strict depth only

find / -iname test -exec sh -c 'd=${1//[^\/]}; echo ${#d} $1' sh {} \; 2>/dev/null | sort -n -r | cut -d" " -f2-

Walking up the directory path

f=/home/bu5hman/test; file=${f##*/}; base=${f%/*}
while [ ! -z $base ]; do
    find $base -maxdepth 1 -name $file
    base=${base%/*}
done

By strict depth only

find / -iname test -exec sh -c 'd=${1//[^\/]}; echo ${#d} $1' sh {} \; 2>/dev/null | sort -n -r | cut -d" " -f2-

Walking up the directory path

f=/home/bu5hman/test; file=${f##*/}; base=${f%/*}
while [ ! -z $base ]; do
    find $base -maxdepth 1 -name $file
    base=${base%/*}
done
added 140 characters in body
Source Link
bu5hman
  • 4.9k
  • 2
  • 16
  • 29

Walking up the directory path

f=/home/bu5hman/test; file=${f##*/}; base=${f%/*}
while [ ! -z $base ]; do
    find $base -maxdepth 1 -name $file
    base=${base%/*}
done

By strict depth only

find / -iname test -exec sh -c 'd=${1//[^\/]}; echo ${#d} $1' sh {} \; 2>/dev/null | sort -n -r | cut -d" " -f2-

Walking up the directory path

f=/home/bu5hman/test; file=${f##*/}; base=${f%/*}
while [ ! -z $base ]; do
    find $base -maxdepth 1 -name $file
    base=${base%/*}
done

Walking up the directory path

f=/home/bu5hman/test; file=${f##*/}; base=${f%/*}
while [ ! -z $base ]; do
    find $base -maxdepth 1 -name $file
    base=${base%/*}
done

By strict depth only

find / -iname test -exec sh -c 'd=${1//[^\/]}; echo ${#d} $1' sh {} \; 2>/dev/null | sort -n -r | cut -d" " -f2-
Source Link
bu5hman
  • 4.9k
  • 2
  • 16
  • 29

Walking up the directory path

f=/home/bu5hman/test; file=${f##*/}; base=${f%/*}
while [ ! -z $base ]; do
    find $base -maxdepth 1 -name $file
    base=${base%/*}
done