Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the tree command under Linux

2025-04-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article is about how to use the tree command under Linux. Xiaobian thinks it is quite practical, so share it with everyone for reference. Let's follow Xiaobian and have a look.

tree is a recursive directory list command that produces a deeply indented list file, which is colored ALA dircolors if ls_colors sets the environment variable and the output is TTY. The tree has been ported and reported to work under the following operating systems: Linux, FreeBSD, OS X, Solaris, HP UX, Cygwin, HP NonStop OS / 2.

1. In ubuntu system, there is no tree command by default. It needs to be installed. Use the following command to install tree. sudo apt-get install tree.

2. First of all, Xiaobian said how to use the tree command. In fact, there is a very simple way to directly view the help about the tree. Enter the following command to view the help information about the tree command tree-help.

3. Let's talk about how to use tree. The easiest way to use it is to enter tree command directly, and it will automatically list the files and folders of the current directory in the form of tree without any parameters. It will automatically list all the files and directories at the depth level below the current directory.

4. Let's talk about how to view subdirectories and files at different levels. Use the command "tree -L 1 " to view only the current first-level directories and files. Use the command "tree -L 2 " to view only the current second-level directories and files. Use the command "tree -L N " to view only the current Nth-level directories and files.

5. The above only shows the current results, but in many cases we want to save this directory structure information, reserve it for ourselves or send it to others. Here we will talk about how to achieve this purpose.

Use the following command to save the directory structure information of the second level subdirectory of the current file to the file/home/xyh/tree.txt

Command:

tree -L 2 > /home/xyh/tree.txt

6. Below, we open the/home/xyh/tree.txt file to see if the results saved in it are the same as those displayed by the command we used before. You can see that the results saved in the file are the input results of using the command "tree-L2".

Thank you for reading! About "Linux tree command how to use" this article is shared here, I hope the above content can have some help for everyone, so that everyone can learn more knowledge, if you think the article is good, you can share it to let more people see it!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report