bash - List all directories not containing a subdirectoriy -
i have solution question
find . -type d -exec sh -c 'test $(find "$0" -maxdepth 1 -type d | wc -l) -eq 1' {} \; -print
i wonder, whether there better (faster) method this. don't start in 'find' find process.
with little more coding following commandshould work:
find . -type d|awk 'nr>1{a[c++]=$0; t=t $0 subsep} end{for (i in a) {if (index(t, a[i] "/") > 0) delete a[i]} (i in a) print a[i]}'
making more readable:
find . -type d | awk 'nr > 1 { a[c++]=$0; t=t $0 subsep } end { (i in a) { if (index(t, a[i] "/") > 0) delete a[i]} (i in a) print a[i] }'
while might more coding in solution in big directory awk based command should run faster embedded find | wc
solution, in question.
performance testing:
i ran on directory containing 15k+ nested sub directories , found awk command considerably faster (250-300% faster) op's find | wc
command.
Comments
Post a Comment