Linux Commands | Misc | tree View Directory Structure
What is tree?
The tree command makes it easy to view a directory structure in the terminal.
You can check the contents of a directory with the ls command, but if you want to check files inside subdirectories, you have to repeatedly use cd and ls. In this situation, the tree command is very useful because it lets you understand the directory structure at a glance.
Install tree
By default, the tree command is not installed.
Install with yum on RHEL / CentOS / Fedora Linux
$ yum install tree
Install with apt-get on Debian / Mint / Ubuntu Linux
$ sudo apt-get install tree
Install with Homebrew on Mac OS
$ brew install tree
Updating Homebrew...
==> Downloading https://homebrew.bintray.com/bottles/tree-1.7.0.yosemite.bottle.1.tar.gz
######################################################################## 100.0%
==> Pouring tree-1.7.0.yosemite.bottle.1.tar.gz
/usr/local/Cellar/tree/1.7.0: 7 files, 113.4KB
tree Usage
Usage
$ tree (options)
View Directory Structure
$ tree
.
├── build.gradle
├── gradle
│ └── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── settings.gradle
└── src
├── main
│ └── java
│ └── Library.java
└── test
└── java
└── LibraryTest.java
7 directories, 8 files
tree Options
| Option | Description |
|---|---|
-a |
Show all files, including hidden files |
-d |
Show only directory structure |
-l |
Follow symbolic links like directories and display them |
-f |
Display with relative paths |
-i |
Display without indentation |
-q |
Display even non-printable ? characters |
-N |
Display all non-printable characters |
-p |
Display permissions |
-u |
Display file owner or UID number |
-g |
Display each file size in bytes |
-h |
Display each file size in a human-readable format |
-D |
Display modification date |
-F |
Append ‘/’, ‘=’, ‘*’, or ‘|’ to entries |
-v |
Sort files in directories alphabetically |
-r |
Sort files in directories in reverse alphabetical order |
-t |
Sort by recently modified files |
-x |
Stay on the current file system |
-n |
Turn color mode off |
-C |
Turn color mode on |
References
- http://yamoo9.net/terminal-tree/
- https://www.cyberciti.biz/faq/linux-show-directory-structure-command-line/