Search code examples
macosbashterminaltreeviewsunos

Folders tree with rights


In OS X and SunOS OS there is no exist the 'bash tree command'.

To plot a tree "graph" of folders i use the following instruction:

find . -type d -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'

Or this to show files too.

find . -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'

But i need another version which contains also the folders rights. Im pretty lost to add on the right side the folder rights. Anyone have any idea ??

Update: There are any option to plot the files inside the folders and their rights too. I'm trying with this command find . -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g' and doing combination with the solution provided by #fedorqui but the result aren't so good.

That's the result obtained with the above command, without rights.

| | |____src
| | | |____cft2exit.c
| | | |____cft2exit_AIX
| | | |____cft2exit_SUN
| | | |____gestidt.c
| | | |____gestidt.h
| | | |____gestidt.o
| | | |____gestidt_AIX
| | | |____gestidt_SUN
| | | |____gestidt_SunOS
| | | |____makefile
| | | |____sem.a
| | | |____ut_sem.c
| | | |____ut_sem.h
| | | |____ut_sem.o
| |____data
| | |____purge.dat
| |____lost+found

Solution

  • You can execute ls -ld for each result of find. It will give you the permissions, other things, and then the file name. If you then pipe to awk, with awk '{print $NF, $1}' you can print both blocks of information. Finally, you pipe to your sed command. All together:

    find . -type d -exec ls -ld {} \; | awk '{print $NF, $1}' | sed -e 's;[^/]*/;|____;g;s;____|; |;g'
    

    Test

    $ find . -type d -exec ls -ld {} \; | awk '{print $NF, $1}' | sed -e 's;[^/]*/;|____;g;s;____|; |;g'
    . drwxrwxr-x
    |____python drwxrwxr-x
    | |____jinja2 drwxrwxr-x
    | | |____bk drwxrwxr-x
    | | |____infiles drwxrwxr-x
    .......
    

    In small steps:

    $ find . -type d -exec ls -ld {} \;
    drwxrwxr-x 7 me me 4096 Aug 15 15:35 .
    drwxrwxr-x 3 me me 4096 Aug 13 14:31 ./python
    drwxrwxr-x 4 me me 4096 Apr 26 15:14 ./python/jinja2
    drwxrwxr-x 2 me me 4096 Apr 19 14:26 ./python/jinja2/bk
    drwxrwxr-x 2 me me 4096 Apr 19 12:54 ./python/jinja2/infiles
    

    and then

    $ find . -type d -exec ls -ld {} \; | awk '{print $NF, $1}' 
    . drwxrwxr-x
    ./python drwxrwxr-x
    ./python/jinja2 drwxrwxr-x
    ./python/jinja2/bk drwxrwxr-x
    ./python/jinja2/infiles drwxrwxr-x