Skip to main content

Show the contents of the current directory as a tree.

# To print files and directories up to 'num' levels of depth (where 1 means the current directory):
tree -L <num>

# To print directories only:
tree -d

# To print hidden files too:
tree -a

# To print the tree without indentation lines, showing the full path instead (use '-N' to not escape whitespace and special characters):
tree -i -f

# To print the size of each node next to it, in human-readable format, with directories displaying their cumulative size (as in the 'du' command):
tree -s -h --du

# To print files within the tree hierarchy, using a wildcard (glob) pattern, and pruning out directories that don't contain matching files:
tree -P '<*.txt>' --prune

# To print directories within the tree hierarchy, using the wildcard (glob) pattern, and pruning out directories that aren't ancestors of the wanted one:
tree -P <directory_name> --matchdirs --prune

# To print the tree ignoring the given directories:
tree -I '<directory_name1|directory_name2>'