With little more coding following commandshould also 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]} for (i in a) print a[i]}'
Making it more readable:
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]}
for (i in a)
print a[i]
}'
While it might look like more coding in this solution but in a big directory this awk based command should run much faster than the embedded find | wc
solution, as in the question.
Performance Testing:
I ran it on a directory containing 15k+ nested sub directories and found this awk command considerably faster (250-300% faster) that the OP's find | wc
command.