Use find's "-printf" feature in combination with sort. See for yourself:
find . -printf "%d %p
"|sort -n
It generates a depth-sorted list (displaying the depth in the first column, file path in the second). This prints in my current dir:
0 .
1 ./bin
1 ./log
1 ./templates
2 ./bin/cc_env
3 ./files/test/mail.txt
If you want to strip the first column, we can use perl:
find . -printf "%d %p
"|sort -n|perl -pe 's/^d+s//;'
and off you go. The perl filter will remove all leading numbers. In case you want to omit directories themselves, use the '-type f' parameter:
find . -type f -printf "%d %p
"|sort -n|perl -pe 's/^d+s//;'
Hint: Study the find manpage for more printf %d-like tricks.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…