Display Directory Hierarchy from Specific Path Ubuntu
This guide explains how to visualize the directory structure within Ubuntu using the command line. You will learn the primary command for generating tree views, how to install necessary tools, and alternative methods for viewing folder hierarchies from a specific path without graphical interfaces.
Use the Tree Command
The most effective way to display a directory hierarchy is using the
tree command. It may not be installed by default on minimal
Ubuntu installations. Install it using the following command:
sudo apt update
sudo apt install treeOnce installed, run the command followed by your target path:
tree /path/to/directoryLimit Directory Depth
To prevent the output from becoming too large, you can limit the
depth of the hierarchy. Use the -L flag followed by the
number of levels you wish to see:
tree -L 2 /path/to/directoryShow Directories Only
If you want to exclude files and only display the folder structure,
add the -d flag:
tree -d /path/to/directoryAlternative Methods
If you cannot install new software, use the find command
which is built into the system. To list directories only:
find /path/to/directory -type dAnother option is using ls recursively, though the
output is less visual:
ls -R /path/to/directory