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.

merged by Michael Mrozek Dec 18 '11 at 23:57

This question was merged with How to name a file in the deepest level of a directory tree because it is an exact duplicate of that question.

  • 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 3:09

Browse other questions tagged or ask your own question.