Command to sort directories after a recursive find

find -type d -name "TC_[0-9][0-9][0-9]*" | sort

That's what I have so far... it finds the appropriate directories and then sorts them. But, when it comes to nested subdirectories, it only sorts relative to the first subdirectory. I want it to sort based on the directory at the end of the path. Does anyone know how to achieve this?

Thanks!

We don't know what Operating System of shell you have.
One idea is to extract the name of the low-level directory and use it as a temporary prefix while we sort.

Also, your "find" needs a start directory parameter. I have used "." in this example. Because I have used ":" as a delimiter this script will not work if a directory name contains a colon.

#!/bin/ksh
(
find . -type d -name "TC_[0-9][0-9][0-9]*" | while read DIR 
do
        DIRB=`basename "${DIR}"`
        echo "${DIRB}:${DIR}"
done
) | sort | cut -d: -f2-

I am using bash/sh. It works !! Thanks alot

Use a combination of basename and dirname to reverse the directories and sort on the new file.

Suppose

a=/a/b/c/d/e

do while $a >""
echo -e `basename $a \c"
a=`dirname $a`
done 
echo -e "\n"