osx - How to measure the depth of a file system path? -


i'm looking way on command line, since not hard task in java or python.

something like:

$ measure_depth /a/b/c/d/e/f 6 $ measure_depth /a 1 

this question functionally equivalent "is there easy way count number of slashes in filename?"

define measure_depth function:

measure_depth() { echo "${*#/}" | awk -f/ '{print nf}'; } 

then, use follows:

$ measure_depth /a/b/c/d/e/f 6 $ measure_depth /a 1 

Comments