linux ls tree code example
Example 1: bash how to print the directory structure in linux
1. Install the tree package with your favorite linux/unix installer, e.g.
sudo apt-get install tree
brew install tree
2. Run tree to see directory structure, e.g.:
tree /directory/to/visualize/
tree -L 1
tree -L 2
tree -L 2 -d
alias tree1='tree -L 1'
alias tree2='tree -L 2'
alias tree3='tree -L 3'
Example 2: linux alternatives to tree
function tree() {
find ${1:-.} | sed -e "s/[^-][^\/]*\// |/g" -e "s/|\([^ ]\)/|-\1/"
}