When blogging recently, it is occasionally necessary to visually list the file directory structure, such as Python's package structure.
So on the Internet search, found a Linux is a good tool--tree
Tree can visually display a multilevel directory structure.
1. Installation method
On Ubuntu directly
sudo Install Tree
2. A few more general uses:
1. Display the directory structure
[email protected] test]# Tree.└──level-1├──L1-file-1. TXT├──L1-file-2. Txt├──level-2-1│├──l21-file-1. Txt│├──level-3-1││└──l31-file-1. Txt│├──level-3-2││└──l32-file-1. Txt│└──level-3-3│└──l33-file-1. Txt├──level-2-2│└──l22-file-1. Txt└──level-2-37Directories,7Files
2. Include hidden files
[Email protected] test]# tree-A.└──level-1├──L1-file-1. TXT├──L1-file-2. txt├──. L1-Hide.dat├──level-2-1│├──l21-file-1. txt│├──. L2-Hide.dat│├──level-3-1││└──l31-file-1. Txt│├──level-3-2││└──l32-file-1. Txt│└──level-3-3│└──l33-file-1. Txt├──level-2-2│└──l22-file-1. Txt└──level-2-37Directories,9Files
3. Depth of control (assuming 3)
[Email protected] test]# tree-l3. └──level-1├──L1-file-1. TXT├──L1-file-2. Txt├──level-2-1│├──l21-file-1. Txt│├──level-3-1│├──level-3-2│└──level-3-3├──level-2-2│└──l22-file-1. Txt└──level-2-37Directories,4Files
4. Show only Directories
[[email protected] test]# tree-d.└──level - 1 ├──level -2 - 1 │ ├──level -3 -1 │ ├──level - 3 -2 │ └──level -3 -3 ├──level -2 -2 └──level -2 - 3 7 directories
5. Filter the files that need to be displayed
# displays only the containing"L2"string of files and filter out the empty directory also filtered out [[email protected] test]# tree-P'*l2*'--Prune.└──level-1├──level-2-1│└──l21-file-1. Txt└──level-2-2└──l22-file-1. txt3Directories,2files# only display does not contain"L2"string of files, and will filter out the empty directory also filtered out [[email protected] test]# [[email protected] test]# tree-I.'*l2*'--Prune.└──level-1├──L1-file-1. TXT├──L1-file-2. Txt└──level-2-1├──level-3-1│└──l31-file-1. Txt├──level-3-2│└──l32-file-1. Txt└──level-3-3└──l33-file-1. txt5Directories,5Files
3. More Options
Options |
Description |
-A |
Displays all files, including hidden files. |
-D |
Displays only the directory. |
-L |
Trace symbolic links, if linked to a directory, is treated as a directory. |
-F |
Displays the full path. |
-X |
Displays only this file system. |
- L level |
Controls the directory depth displayed. |
-R |
In the subordinate directory, execute the tree command again and add the '-o 00tree.html ' option to use with-l,-h. |
-P Pattern |
Only files that match the pattern (not the directory) are displayed, and simple regular expressions are supported. |
-I. pattern |
In contrast to-p, only files with no matching pattern are displayed. |
--ignore-case |
When the-p or-i option is used, the case is ignored. |
--matchdirs |
When the-p option is used, the file name contains the full path. |
--prune |
Empty directories are not displayed and are considered empty if no directories are required to be displayed after-p or-I. |
--noreport |
The last statistic is not displayed. |
--charset CharSet |
Specifies the character set. |
--filelimit # |
Filter out directories that have more than # of files. |
--timefmt FMT |
Prints the modified time of the file in the specified format. |
-O filename |
Output the results to a file. |
-Q |
Use a question mark instead of a non-printable character. |
-N |
Use octal instead of non-printable characters. |
-Q |
Enclose the file name in quotation marks. |
-P |
Displays the type and permissions of the file. |
-U |
Displays the user name or UID to which the file belongs. |
-G |
Displays the group or GID to which the file belongs. |
-S |
Displays the size of the file, in bytes. |
-H |
Displays the size of the file, using a more user-friendly display. |
--si |
Displays the size of the file, similar to-H but using biggest units (1k=1000). |
--du |
For a directory, displays the cumulative size of all the files under it. |
-D |
Displays the last modified time of the file. |
-F |
Similar to ls-f, for different file types, add different characters at the end. |
--inodes |
Displays the index node of the file. |
--device |
Displays the device number to which the file belongs. |
-V |
The list of files displayed is sorted by version. |
-T |
The list of files displayed is sorted by the last modified time. |
-C |
The list of files displayed is sorted by the last state change time. |
-U |
Sorting is not processed. |
-R |
The reverse output list. |
--dirsfirst |
Priority display table of contents (same level) |
--sort[=name] |
Specifies the sort method, name (default), CTime, mtime, size, version. |
-I. |
Do not indent in the output. |
-A |
Uses the ASCII horizontal line character to denote indentation. |
-S |
Use the CP437 line character to indicate indentation. |
-N |
Turns off the color display. |
-C |
Turns on the color display. |
-X |
Enables the output to be in XML format. |
-j |
Enable JSON format to output. |
-H basehref |
Enables HTML format output and contains the basic HTTP link address. |
-T title |
In HTML format output, set the caption and H1 tag header |
--nolinks |
In HTML format output, hyperlinks are not exported. |
Linux Talk: Tree-shaped display multilevel directory--tree