Don't have tree, need advise to differentiate dir from file from this alternative that uses find

Hi,

I don't have tree on the Solaris server and our SA don't want to install it. I found this example from One Line Linux Command to Print Out Directory Tree Listing | systemBash that more or less does what I am mainly looking for.

Example run is as below:

$: find ./ | sed -e 's/[^-][^\/]*\//--/g;s/--/ |-/'
 |-
 |-files
 |---lib
 |-----libserver12.a
 |-------qksvc.o
 |-etc
 |---config
 |-----actions.xml
 |-----inventory.xml
 |-README.txt
$: ls -ld *
-rwxr-xr-x   1 oracle   dba         6078 Mar 15  2017 README.txt
drwxr-xr-x   3 oracle   dba         4096 Mar 15  2017 etc
drwxr-xr-x   3 oracle   dba         4096 Mar 15  2017 files
$: ls -ld files/*
drwxr-xr-x   3 oracle   dba         4096 Mar 15  2017 files/lib
$: ls -ld files/lib/*
drwxr-xr-x   2 oracle   dba         4096 Mar 15  2017 files/lib/libserver12.a
$: ls -ld files/lib/libserver12.a/*
-rwxr-xr-x   1 oracle   dba       164056 Mar 15  2017 files/lib/libserver12.a/qksvc.o

I want to know if it is possible to change the same one liner so that the output is able to differentiate between a directory to a file. Maybe for example if it is a directory, it displays a * or [DIR] at the end of it.

Please advise. Thanks.

Just do find -type f and you'll know that every top-level name you find is a file and everything beneath must be a folder, i.e. /path/to/filename

2 Likes

The following versions are closer to the original and help to see the directories better:

find . | sed 's#[^/]*/#|  #g; s#^\([| ]*|\)  #\1--#'
find . | sed 's#[^/]*/#|  #g; s#^\([| ]*\)|  #\1+--#'
2 Likes