With fewer encodings, the following commands should 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]}'
Make 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] }'
Although there may be more code in this solution, this awk-based command should work much faster in a large directory than the find | wc find | wc , as in the question.
Performance Testing:
I ran it in a directory containing 15k + subdirectories, and found this awk command much faster (250-300% faster) than the OP find | wc find | wc .
source share