Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 669
Jorge Vega Sánchez Avatar asked Mar 22 '23 18:03

Jorge Vega Sánchez


2 Answers

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
like image 73
fedorqui 'SO stop harming' Avatar answered Apr 01 '23 06:04

fedorqui 'SO stop harming'


On OS X you can install tree, using homebrew:

brew install tree

or, using macports:

sudo port install tree

and then, to view directories with permissions:

$ tree -p -d

Sample output:

.
├── [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
like image 42
keyser Avatar answered Apr 01 '23 08:04

keyser