4

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
Jorge Vega Sánchez
  • 7,430
  • 14
  • 55
  • 77

2 Answers2

5

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
fedorqui
  • 275,237
  • 103
  • 548
  • 598
  • doesn't find have a '-ls' option ?? – Dru Aug 15 '13 at 20:56
  • @Dru not that I know of. – fedorqui Aug 16 '13 at 08:05
  • Is there any option to show folders and also the files into their folder, all with their rights. I'm trying with your solution combining with this other command find . -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g' , but the result is not so good. – Jorge Vega Sánchez Dec 18 '13 at 09:01
  • @JorgeVegaSánchez Mmmm I am not sure I understand what you mean. Can you update your question with a sample input/output? – fedorqui Dec 18 '13 at 09:40
  • @JorgeVegaSánchez now I see. But note that my solution was providing the rights of the files next to each line. By using `find . -type d -exec ls -ld {} \;` they appear. – fedorqui Dec 18 '13 at 11:01
  • Yes, I try using this part of your solution changing the ls -ld by ls -l but the output was weird. I can see the rights but I can see the folder of a group of files. – Jorge Vega Sánchez Dec 18 '13 at 11:03
  • 1
    @JorgeVegaSánchez it is important to use `ls -ld` because the `-d` gives info about the directory. Otherwise with `ls -l` you are printing the content of every particular directory. – fedorqui Dec 18 '13 at 11:04
  • That's the main problem, combine both or something like this to show folders and files into with the rights on the right side. – Jorge Vega Sánchez Dec 18 '13 at 13:43
2

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
keyser
  • 18,829
  • 16
  • 59
  • 101