What is the Linux tree command, and how is it used?
Tree command show contents of directories in tree format structure.
4 min read
Table of contents
Tree command help to list out the contents of directories in a tree-like format. Tree command provides tree diagram in-depth listing files.
Most commonly use tree commands in writing documentation, and secondly, we use tree commands to understand project directory structure.
If you use Linux and think the tree command is not your help. Because I have UI to understand every directory. that time, you're mistaken.
Most of the time app or project is very big. Because of many files, folders, or directories in the app, you do not observe and understand what happens in the app and which folders and files are stored. Secondly, where I store my custom components are directories and folders.
You also face the same problem. Then you are right place. You understand the tree command concept by example.
The most common example. When I build React.js open-source admin dashboard, I create many custom components and directories for my app., like header, footer, nav, and card directories, to separate every custom component and sass file.
This structure, I understand. But this is an open-source project. When I write documentation for the open-source react dashboard on GitHub. Then I manually design an image to tell others which folder to have a header component you change and where is asset folder is.
I just run the tree command to design a simple tree structure in my command terminal and use it in your documentation.
How to install the tree command?
Firstly check the tree command install by default in your system. so firstly, run it if you face an not found error. After a run command, that means tree command not installed in your system firstly install it.
Install tree command in your system in many ways.
You use it to install the tree command on RHEL/CentOS/Fedora Linux. We have to type the following command on the terminal:
yum install treecopy success
If we want to install a tree command in the Apple OS system, then type:
Brew install treecopy success
Install tree command with the help of snapcraft or snap.
sudo snap install treecopy success
The apt command is a common way to install any software and package and widely use it in your system.
sudo apt install treecopy success
How to use the tree command?
Tree program available for Unix and Unix-like systems. That means it is available for all the different platforms like Linux, Windows, and mac os.
Tree command also supports all the Linux distros.
Using the tree command is very easy. You write-tree command in your terminal.
tree Or sudo treecopy success
Flag and Options
Tree command also provides some flag or option to enhance the operating speed. We discuss some tree command options or flags. Whatever you say, both mean the same.
Some tree flags are handy, and you also use daily basis in life. Other flags are more advanced for us. if you are interested to learn more, I recommend using the help command and man command
First, write-tree command. then write directory name
This -a flag print All files. By default, the tree does not print hidden files.
This -d flag helps to show only directories List.
This -f flag print the full path prefix for each file and directories.
Tree -s flag prints the size in bytes of each file and directory.
The help flag prints help messages in your terminal and automatic exit.
Man command help to print manual page information on the terminal.
Remove or uninstall the tree command in the system
You install the tree command help of the apt command. You uninstall or remove the tree command package in just one command.
sudo apt remove --purge treecopy success
- Remove flag tell the command to remove this package.
- --purge flag help to remove everything related to tree commands like file, folder, and configuration.