linux命令_tree,执行tree指令,它


tree

Linux tree命令用于以树状图列出目录的内容。

执行tree指令,它会列出指定目录下的所有文件,包括子目录里的文件。

语法

tree [-aACdDfFgilnNpqstux][-I <范本样式>][-P <范本样式>][目录...]

参数说明

  • - -a   显示所有文件和目录。
    - -A   使用ASNI绘图字符显示树状图而非以ASCII字符组合。
    - -C   在文件和目录清单加上色彩,便于区分各种类型。
    - -d   显示目录名称而非内容。
    - -D   列出文件或目录的更改时间。
    - -f   在每个文件或目录之前,显示完整的相对路径名称。
    - -F   在执行文件,目录,Socket,符号连接,管道名称名称,各自加上"*","/","=","@","|"号。
    - -g   列出文件或目录的所属群组名称,没有对应的名称时,则显示群组识别码。
    - -i   不以阶梯状列出文件或目录名称。
    - -L level   限制目录显示层级。
    - -l   如遇到性质为符号连接的目录,直接列出该连接所指向的原始目录。
    - -n   不在文件和目录清单加上色彩。
    - -N   直接列出文件和目录名称,包括控制字符。
    - -p   列出权限标示。
    - -P<范本样式>   只显示符合范本样式的文件或目录名称。
    - -q   用"?"号取代控制字符,列出文件和目录名称。
    - -s   列出文件或目录大小。
    - -t   用文件和目录的更改时间排序。
    - -u   列出文件或目录的拥有者名称,没有对应的名称时,则显示用户识别码。
    - -x   将范围局限在现行的文件系统中,若指定目录下的某些子目录,其存放于另一个文件系统上,则将该子目录予以排除在寻找范围外。
    

以树状图列出当前目录结构。可直接使用如下命令:

[root@localhost pgsql] tree
.
├── assets
│   └── postgresql-12.10.tar.gz
├── conf
│   ├── pg_hba.conf
│   ├── postgresql
│   └── postgresql.conf
├── install.py
├── install.pyc
└── services
    └── postgresql-12.service

3 directories, 7 files

显示2层目录:

[root@localhost opt] tree -L 2
.
├── nta
│   ├── pom.xml
│   └── src
├── py_mysql
│   ├── bin
│   ├── core
│   ├── db
│   ├── doc
│   ├── log
│   ├── README.md
│   ├── templates
│   └── venv
├── Python-3.8.3
│   ├── aclocal.m4
│   ├── build
│   ├── CODE_OF_CONDUCT.md
│   ├── config.guess
│   ├── config.log
│   ├── config.status
│   ├── config.sub
│   ├── configure
│   ├── configure.ac
│   ├── Doc
│   ├── Grammar
│   ├── Include
│   ├── install-sh
│   ├── Lib
│   ├── libpython3.8.a
│   ├── LICENSE
│   ├── m4
│   ├── Mac
│   ├── Makefile
│   ├── Makefile.pre
│   ├── Makefile.pre.in
│   ├── Misc
│   ├── Modules
│   ├── Objects
│   ├── Parser
│   ├── PC
│   ├── PCbuild
│   ├── Programs
│   ├── pybuilddir.txt
│   ├── pyconfig.h
│   ├── pyconfig.h.in
│   ├── python
│   ├── Python
│   ├── python-config
│   ├── python-config.py
│   ├── python-gdb.py
│   ├── README.rst
│   ├── setup.py
│   └── Tools
├── Python-3.8.3.tgz

40 directories, 34 files

只显示目录,不显示文件:

[root@localhost pgsql] tree -d
.
├── assets
├── conf
└── services

3 directories

加颜色进行区分:

列出文件或目录大小

[root@localhost steps] tree -s -L 2
.
├── [         85]  basic
│   ├── [         19]  assets
│   ├── [         31]  conf
│   ├── [       1213]  install.py
│   ├── [       1644]  install.pyc
│   └── [         31]  services
├── [         55]  compiler
│   ├── [       3950]  install.py
│   ├── [       4093]  install.pyc
│   └── [         20]  rpms
├── [        144]  custom_python
│   ├── [        254]  assets
│   ├── [         40]  conf
│   ├── [       3067]  install.py
│   ├── [       3653]  install.pyc
│   ├── [         31]  python3-packages
│   ├── [        108]  python-packages
│   ├── [         20]  rpms
│   └── [         29]  services

按时间排序

[root@localhost steps] tree -t -L 1
.
├── params.py
├── compiler
├── dnsmasq
├── elasticsearch
├── go
├── params.pyc
├── nginx
├── optimization

本文来自博客园,作者:ivanlee717,转载请注明原文链接:https://www.cnblogs.com/ivanlee717/p/16312582.html

相关内容