Rights Folder Tree

On OS X and SunOS, there is no bash tree command.

To build a tree of β€œdiagrams” of folders, I use the following instruction:

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

Or is it also for displaying files.

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

But I need another version that also contains folder permissions. Im pretty lost to add folder right on the right. Does anyone have an idea?

Update: It is possible to print files inside folders and their rights. I am trying to execute this find . -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g' find . -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g' find . -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g' and make a combination with the solution provided by #fedorqui, but the result is not so good.

This is the result obtained using the specified command without permissions.

 | | |____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 
+4
source share
2 answers

You can do ls -ld for each find result. It will give you permissions, other things, and then the file name. If you then connect to awk, with awk '{print $NF, $1}' you can print both blocks of information. Finally, you connect to the sed command. 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 
+5
source

On OS X, you can install tree using homebrew :

 brew install tree 

or using macports :

 sudo port install tree 

and then to browse directories with permissions:

 $ tree -p -d 

Output Example:

 . β”œβ”€β”€ [drwxr-xr-x] folder1 β”‚  └── [drwxr-xr-x] folder2 β”‚  └── [drwxr-xr-x] folder3 β”‚  └── [drwxr-xr-x] folder4 └── [drwxr-xr-x] folder5 β”œβ”€β”€ [drwxr-xr-x] folder6 └── [drwxr-xr-x] folder7 
+2
source

Source: https://habr.com/ru/post/1497268/


All Articles