linux list all folders and subfolders 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: get list of all files in folder and subfolders python
for path, subdirs, files in os.walk(root):
for name in files:
print os.path.join(path, name)