Friday, October 31, 2008

Determine the greatest depth of subdirectories in a hierarchy

I found this thread on comp.unix.shell interesting.  And I particularly liked this solution.

$ x=./a/b/c/d/e/f
$ y=${x//[^\/]}
$ echo $y ${#y}
////// 6


Nicely done within the shell itself without calling anything anew.  And the thread itself has other solutions that may be of use to people who need to traverse and check files in directories.