The simplest solution:
$ echo * */* */*/* */*/*/* */*/*/*/* */*/*/*/*/* aa/ba/b/ca/b/c/d1 a/b/c/d2 a/b/c/d1/ea/b/c/d2/ea/b/c/d1/e/fa/b/c/d2/e/f
Or in the column:
$ echo * ***** **
The depth of the tree is hardcoded in the example, but you can write a small script and make it more flexible:
A="*" while true do B=$(echo $A) [ "$B" = "$A" ] && break echo $B A="$A/*" done | tr ' ' '\n'
Usage example:
$ A="*"; while true; do B=$(echo $A); [ "$B" = "$A" ] && break; echo $B; A="$A/*"; done | tr ' ' '\n' a a/b a/b/c a/b/c/d1 a/b/c/d2 a/b/c/d1/e a/b/c/d2/e a/b/c/d1/e/f a/b/c/d2/e/f
Examples for a tree:
$ mkdir -pa/b/c/d{1,2}/e/f $ tree . . โโโ a โโโ b โโโ c โโโ d1 โ โโโ e โ โโโ f โโโ d2 โโโ e โโโ f 9 directories, 0 files
Find / in-depth solutions obviously won't work, because find will display the subtrees one by one. The -depth key indicates in which direction the subtree should be displayed. But this does not mean, of course, that the output will be sorted by depth.
$ find . . ./a ./a/b ./a/b/c ./a/b/c/d2 ./a/b/c/d2/e ./a/b/c/d2/e/f ./a/b/c/d1 ./a/b/c/d1/e ./a/b/c/d1/e/f $ find . -depth ./a/b/c/d2/e/f ./a/b/c/d2/e ./a/b/c/d2 ./a/b/c/d1/e/f ./a/b/c/d1/e ./a/b/c/d1 ./a/b/c ./a/b ./a .
As you can see, in both cases the answer is incorrect (with and without -find ).
source share