How to use the tree plug-in in CentOS

Time:2020-7-5

The tree plug-in consumes CPU and memory, so you need to pay attention when using it.

Tree installation:

yum -y install tree

Or is it

sudo apt-get install tree

When using the directory name of tree, the tree structure of the directory can be displayed. An example is as follows:

Unload command of tree

yum -y remove tree

Common usage:

Tree – a displays all
Tree – D displays only directories
Tree – L n n stands for number.. indicates how many layers to display
Tree – f displays the full path

Of course, tree supports redirection to files

tree -L 4 > dirce.doc It can generate documents in utf8 format. We can also view it under windows

Note: the generated TXT or other files are garbled when opened under win… At this time, we need to select the character encoding as UTF-8.. of course, UTF-8 is the default character set under Linux

Detailed explanation of tree command under inux

Command format
Tree < option or parameter > < partition or Directory >

(1) The longest parameter or option used by tree

-A displays all files and directories.
[root @liyao~]# tree -a
.
|– .bash_logout
|– .bash_profile
|– .bashrc
|– .cshrc
|– .gconf
|   `– apps
|       |– %gconf.xml
|       `– gnome-session
|           |– %gconf.xml
|           `– options
|               `– %gconf.xml
|– .gconfd
|   `– saved_state
|– .tcshrc
|– anaconda-ks.cfg
|– install.log
`– install.log.syslog
**************************************************************************************
-D displays the directory name, not the content.
[root @liyao~]# tree -d
.
`– liyao
1 directory

*****************************************************************************
-F displays the complete relative path name before each file or directory.
[[email protected] ~]# tree -f
.
|– ./anaconda-ks.cfg
|– ./install.log
|– ./install.log.syslog
`– ./liyao
1 directory, 3 files
*****************************************************************************
-F add “*”, “/”, “=”, “@”, and “|” in the executable file, directory, socket, symbolic connection, and pipeline name.
[[email protected] ~]# tree -F
.
|– anaconda-ks.cfg
|– install.log
|– install.log.syslog
`– liyao/

1 directory, 3 files
*****************************************************************************
-R is in reverse order
[[email protected] ~]# tree -r
.
|– liyao
|– install.log.syslog
|– install.log
`– anaconda-ks.cfg

1 directory, 3 files
*****************************************************************************
-T sort by the change time of files and directories.
[[email protected] ~]# tree -t
.
|– liyao
|– anaconda-ks.cfg
|– install.log
`– install.log.syslog

1 directory, 3 files
[[email protected] ~]# ls -l
total 56
-rw——- 1 root root  1012 Jul  3 21:43 anaconda-ks.cfg
-rw-r–r– 1 root root 27974 Jul  3 21:43 install.log
-rw-r–r– 1 root root  4708 Jul  3 21:43 install.log.syslog
drwxr-xr-x 2 root root  4096 Jul  3 23:30 liyao
*****************************************************************************
-L n only displays N-level directory (n is a number)
[[email protected] ~]# tree -L 2
.
|– anaconda-ks.cfg
|– install.log
|– install.log.syslog
`– liyao
   `– baobao

2 directories, 3 files
*****************************************************************************
–The dirsfirst directory is displayed in the front, and the file is displayed after
[[email protected] ~]# tree –dirsfirst
.
|– liyao
|   `– baobao
|– anaconda-ks.cfg
|– install.log
`– install.log.syslog

2 directories, 3 files

#####################################################################
(2) Can be added parameters, but not often used

-A displays the tree view using Asni drawing characters instead of combining ASCII characters.
-C adds color to the list of files and directories to distinguish various types.
-D lists when the file or directory was changed.
-G list the group name of the file or directory. If there is no corresponding name, the group ID will be displayed.
-I do not list file or directory names in a ladder.
-I do not display file or directory names that match the template style.
-L if you encounter a directory with a symbolic connection, list the original directory that the connection points to directly.
-N do not color the list of files and directories.
-N directly lists file and directory names, including control characters.
-P lists the permission label.
-P displays only the file or directory names that match the template style.
-Q replaces the control character with a “? Sign to list file and directory names.
-S lists the file or directory size.
-U lists the name of the owner of the file or directory. If there is no corresponding name, the user ID is displayed.
-X limits the scope to the current file system. If some subdirectories under a specified directory are stored on another file system, they will be excluded from the search scope.

Recommended Today

Java Engineer Interview Questions

The content covers: Java, mybatis, zookeeper, Dubbo, elasticsearch, memcached, redis, mysql, spring, spring boot, springcloud, rabbitmq, Kafka, Linux, etcMybatis interview questions1. What is mybatis?1. Mybatis is a semi ORM (object relational mapping) framework. It encapsulates JDBC internally. During development, you only need to pay attention to the SQL statement itself, and you don’t need to […]