G
G
glaucidium2019-12-04 13:57:47
linux
glaucidium, 2019-12-04 13:57:47

How to get a hierarchical list of paths sorted by file type and alphabetically?

Hello!
How to get a hierarchical list of full paths, where files would go first, then directories, and each file type in alphabetical order?
An example of the desired order:

spoiler
settings/
settings/dolphinrc.txt
settings/vimrc.txt
settings/яндекс.txt
settings/fish/
settings/fish/fish_prompt_new.txt
settings/fish/fish_prompt_old.txt
settings/Menu/
settings/Menu/contents/
settings/Menu/contents/ui/
settings/Menu/contents/ui/AppContextMenu.txt
settings/Menu/contents/ui/XdgPathsLoader.txt
settings/Шрифты/

What I tried:
find $path - gives paths randomly.
find $path -depth - the folder where it is now really prints at the end. But the contents of the folder are still given out randomly.
find $path | sort - sorting by alphabet, depth, parent path did not give the desired one.
tree -fi $path Gives paths randomly.
tree -fi --dirsfirst $path is what you need! But folders come first. Eh if there was an option --filefirst.
du -a $path Gives paths randomly.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
G
glaucidium, 2019-12-04
@glaucidium

The task turned out to be not trivial.
The most beautiful solution is to run find on folders, and put -exec into it, find on files.
Just output a list of paths, with a breadth-first traversal.
List of paths with formatting
List of paths with processing
Related links:
https://stackoverflow.com/questions/12503958/recur...
https://stackoverflow.com/questions/539583/how-do-...
https://unix.stackexchange.com/questions /279895/ho...
https://stackoverflow.com/questions/1086907/can-fi...
https://github.com/tavianator/bfs - wrote a recursive find

Z
Zzzz9, 2019-12-04
@Zzzz9

I didn't understand what you want. What does not suit for example:
find path -print | sort-g

S
SOTVM, 2019-12-04
@sotvm

algorithm/loop
found all directories (recursively)
for each directory displayed a list of its files + the name of the directory itself,
go to that until they sorted through the FSE found.
solvable even through finde with the right parameters

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question