2

Possible Duplicate:
How to name a file in the deepest level of a directory tree

How do I get this script to work? The goal is to find the directory at the deepest level in the directory tree and print the name of a file, a random file, maybe the first.

find -type d | declare COUNT=-1; declare P=""; while read LINE ; 
do
   echo $LINE
   declare C
   C=$(echo $LINE | cut -c3- | sed "s/\//\n\//g" | grep '/' -c)
   echo $C
   if [ $COUNT -gt $C ]
   then
       let COUNT=$C
       let P=$LINE
       echo "Done"
   fi
done

Better solutions are also welcome but they should be one-liners.

  • Sorry. I was seeking a quick answer by asking my previous question in another way. I know that one is not supposed to post duplicate questions, or at least questions very similar to existing ones.

    Will not do it again.

    – Robert Sundström Dec 18 '11 at 03:09

0 Answers0