Search code examples
linuxtreecommand-line-interface

Way to visualize as tree a list of paths?


I'd like to see a list of paths in a textfile as a tree in the command line.

I know about the tree utility in gnu/linux, but it seems to default to listing files in the filesystem. Is there a way to give it my list of paths from file so it builds its tree visualization from that instead?


Solution

  • Is the list of paths in the following format, like the output from the "find" command?

    .
    ./aaa
    ./aaa/bbb
    ./aaa/ccc
    ./ddd
    ./ddd/eee
    

    For example, using the "awk" command, I think you can get a format similar to the output of tree.

    $ cat paths.txt | sort | awk '{n=split($0,a,/\//);for(i=1;i<n-1;i++)printf("|   ");if(n>1){printf("+-- ")}print a[n]}'