DEV Community

Matt Kenefick
Matt Kenefick

Posted on

lstree: list directory in structured format

Snippet called lstree

function lstree(){
    ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/   /' -e 's/-/|/';
}
Enter fullscreen mode Exit fullscreen mode

Put this in your .bashrc or .bash_profile and this will give you a directory breakdown that looks like this:

/my/folder> lstree

|-data
|---nginx
|-----cache
|-etc
|---default
|---nginx
|-----conf.d
|-----sites-enabled
|-----sites-templates
|---ssl
|-----certs
|---varnish
|-----html
|-----lua
|-provision
|---mysql
|-----init
|-usr
|---local
|-----etc
|-------docker-original
|---------php-fpm.d
|-------php
|-------php-fpm.d
|-var
|---lib
|-----mysql
|-------mysql
|-------performance_schema
|-------sys

Remember to re-source your bash file after adding it:

source ~/.bashrc
Enter fullscreen mode Exit fullscreen mode

Top comments (0)