I've been trying to sort output with either tree
or find
, and end up getting about the same results each time of drilling down to deeper directories before files higher up in the tree. What I'm trying to do is store the directories of interest in a lua table with the directory as the key for sub tables of files.
I'm using tree -fi -noreport {Foo,Baz}
Foo
Foo/Foo.Build.cs
Foo/Private
Foo/Private/Foos
Foo/Private/Foos/Bars
Foo/Private/Foos/Bars/BaseBar.cpp
Foo/Private/Foo.cpp
Foo/Private/FOOPCH.h
Baz
Baz/Baz.Build.cs
I want the results to look like:
Foo
Foo/Foo.Build.cs
Foo/Private
Foo/Private/Foo.cpp
Foo/Private/FOOPCH.h
Foo/Private/Foos
Foo/Private/Foos/Bars
Foo/Private/Foos/Bars/BaseBar.cpp
Baz
Baz/Baz.Build.cs
tree fi -noreport {Foo,Baz} | sort -t '/'
isn't working. I tried using the solution from this thread, which is tree | awk '{print gsub("/","/"), $0}' | sort -n | cut -d' ' -f2-
. If I do that I lose the relationship between directories and files.
How can I sort so files at the same depth show up before directories?
find
with the -depth option?