I\'m trying to use GNU find to find only the directories that contain no other directories, but may or may not contain regular files.
My best guess so far has been:
This awk
/sort
pipe works a bit better than the one originally proposed in this answer, but is heavily based on it :) It will work more reliably regardless of whether the path contains regex special characters or not:
find . -type d | sort -r | awk 'index(a,$0)!=1{a=$0;print}' | sort
Remember that awk
strings are 1-indexed instead of 0-indexed, which might be strange if you're used to working with C-based languages.
If the index of the current line in the previous line is 1 (i.e. it starts with it) then we skip it, which works just like the match of "^"$0
.