tree command a utility used to display the contents of directories in a tree-like, hierarchical format.
tree command may not be pre-installed on all Linux distributions. To install it use
# Debian/Ubuntu sudo apt install tree
# Display current directory tree # Display a specific directory tree /path/to/directory
Use -d
to show only directory
cheulong@master-node:~/parent$ tree -d . ├── child1 ├── child2 ├── child3 ├── child4 └── child5
Use -f
to show full path prefix for each file
cheulong@master-node:~/parent$ tree -f . ├── ./child1 │ └── ./child1/text.txt ├── ./child2 ├── ./child3 ├── ./child4 └── ./child5
Use -p
to show permission for each file
cheulong@master-node:~/parent$ tree -p [drwxrwxr-x] . ├── [drwxrwxr-x] child1 │ └── [-rw-rw-r--] text.txt ├── [drwxrwxr-x] child2 ├── [drwxrwxr-x] child3 ├── [drwxrwxr-x] child4 ├── [drwxrwxr-x] child5 └── [-rw-rw-r--] file
Use -L <level
to limit the display depth to a specified level.
cheulong@master-node:~/parent$ tree -L 1 . ├── child1 ├── child2 ├── child3 ├── child4 ├── child5 └── file
Use -sh
to show size for each file
cheulong@master-node:~/parent$ tree -sh [4.0K] . ├── [4.0K] child1 │ └── [ 0] text.txt ├── [4.0K] child2 ├── [4.0K] child3 ├── [4.0K] child4 ├── [4.0K] child5 └── [ 225] file
Other Option
-a: Include hidden files and directories (those starting with a dot).
-F: Append a forward slash (/) to directory names and an asterisk (*) to executable files.
--prune: Exclude empty directories from the output.
-u: Print the username (or UID) of each file.
-g: Print the group name (or GID) of each file.
Leave a comment if you have any questions.
===========
Please keep in touch
Portfolio
Linkedin
Github
Youtube
Top comments (0)