Display a Directory Tree on Linux
A directory tree makes project and filesystem structure easier to understand than a flat list of paths. The dedicated tree utility is usually the clearest tool for this job.
Use tree
treeExample output:
.
└── folder1
├── subfolder1
│ └── file1.txt
└── subfolder2
└── file2.txtInclude hidden entries:
tree -aLimit recursion depth:
tree -L 2 /path/to/directoryShow directories only:
tree -dInstall the package if necessary:
sudo apt install tree # Debian/Ubuntu
sudo dnf install tree # Fedora/RHEL-family systems where availableUse find When tree Is Unavailable
A plain recursive path listing can be generated with:
find /path/to/directory -printGNU find can also format depth information for custom reports, but reproducing a full tree drawing correctly in shell code is more complicated than it first appears.
Avoid Parsing Recursive ls for Automation
Pipelines that parse ls -R can break on filenames containing unusual whitespace, newlines, or other characters. tree is appropriate for human-readable display; find with null-delimited output is a better foundation for scripts that must handle arbitrary filenames safely.
find /path/to/directory -print0Conclusion
Use tree when you want a readable visualization and find when you need scriptable traversal. Both are clearer and more robust than building a directory hierarchy by parsing recursive ls output.