how to see directory tree structure in Linux
using tree
command we can see directories in a tree structure under Linux systems.
installation of tree
command is very easy
mac installation
we can install it via brew
tool in mac system. Homebrew is the package manager for macOS.
# install it via brew
brew install tree
fedora/centos installation
# install it via yum
yum install tree
ubuntu installation
# install it via apt-get
sudo apt-get install tree
usages
syntax is:
# show current directory in tree format
tree
# shows target directory in tree format
tree path/to/target
# see tree structure for /tmp
tree /tmp
there is a couple of option you can use with tree
command which is very helpful.
with the -a
option to see all files for a directory, tree
command default behavior does not print hidden files. If you have the use case to see hidden files use the -a
option.
with the -d
option, it lists only directories.
with the -C
option you can colorize the output.
# to see all files including the hidden one
tree -a /path
# see all directories
tree -d /path
# see colorful print
tree -C /path
sample prints:
# show tree structure under /tmp directory
# without option, list all directories and files, exclude hidden one
tree /tmp
#=>
/tmp
├── com.apple.launchd.UxDQO8waNH
│ └── Render
├── com.apple.launchd.V9whkbDUNq
│ └── Listeners
└── powerlog
# with -a option, list all directories, files and hidden files
tree -a /tmp
#=>
/tmp
├── .s.PGSQL.5432
├── .s.PGSQL.5432.lock
├── com.apple.launchd.UxDQO8waNH
│ └── Render
├── com.apple.launchd.V9whkbDUNq
│ └── Listeners
└── powerlog
tree
# with -d option, list only directories
tree -d /tmp
#=>
/tmp
├── com.apple.launchd.UxDQO8waNH
├── com.apple.launchd.V9whkbDUNq
└── powerlog