Skip to content

[Linux] Using “tree” command to visualize the folder hierarchy

Last Updated on 2021-08-01 by Clay

If we want to see the folder hierarchy in Linux, maybe we can use the tree command to visualize it. There are similar command in Windows/MacOS.

In fact, I noticed this command because I was writing a blog. For example, when I’m writing an article about Machine Learning, if I don’t have a useful tool for visualizing folders, I often need to draw a path diagram to describe the path of data —— by myself.

Actually it’s very tiring.

But now if the tree command is used, the path to display the data is much more convenient. Whether you want to check path for data or making a slide, it’s a useful tool.

It’s hard to understand directly, it’s take a look for a example.


Example

If you use tree command in the first time, maybe you need to use the following command to install it.

sudo apt install tree

And then we use the following format to use it:

tree FOLDER

You can also add the number layers displayed by the -L parameter command. For example, I want to check my folder PycharmProjects but it has too many small files. So I specified that only the first layer is displayed:

tree -L 1 PycharmProjects/

Output:

If you need to analyze the data, it can also temporarily stored in the log file.

tree -L 1 PycharmProjects/ > log

In short, this is really a convenient and good command! I can easily display the folder structure in the future.

Tags:

Leave a ReplyCancel reply

Exit mobile version