Recently, I found a really elegant solution to display a file tree using the ls command. I like is so much that I feel the need to share it. The code is:

ls -R | grep “:$” | sed -e ‘s/:$//’ -e ‘s/[^-][^\/]*\//–/g’ -e ‘s/^/ /’ -e ‘s/-/|/’

It displays files as follows:


I got this code from and you will also find a ready to go shell script there.

If you want to add this your bashrc to create an alias, you would run into your problem since bash doesn’t allow single quotes inside inside single quotes even if they are escaped with backslash.

By master