3

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?

2
  • have you run find with the -depth option?
    – Jeff Schaller
    Commented Mar 2, 2017 at 0:25
  • Yeah, I've done that it doesn't exactly give me what I'm looking for.
    – ZeroPhase
    Commented Mar 2, 2017 at 1:08

1 Answer 1

3

Display the directory names first, then jump in and display only filenames:

find . ! -name . -type d -print -exec sh -c 'find "$1" -maxdepth 1 ! -type d' {} {} \;
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .