DEV Community

Matt Kenefick
Matt Kenefick

Posted on

2 1

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)

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay