linux 命令之tree

$ tree 命令需要自行安装。

安装tree:
mac:
$ brew install tree

centos:
$ yum install tree

获取帮助文档:

$ tree --help
usage: tree [-acdfghilnpqrstuvxACDFQNSUX] [-H baseHREF] [-T title ] [-L level [-R]]
        [-P pattern] [-I pattern] [-o filename] [--version] [--help] [--inodes]
        [--device] [--noreport] [--nolinks] [--dirsfirst] [--charset charset]
        [--filelimit[=]#] [--si] [--timefmt[=]<f>] [<directory list>]
  ------- Listing options -------
  -a            All files are listed.
  -d            List directories only.
  -l            Follow symbolic links like directories.
  -f            Print the full path prefix for each file.
  -x            Stay on current filesystem only.
  -L level      Descend only level directories deep.
  -R            Rerun tree when max dir level reached.
  -P pattern    List only those files that match the pattern given.
  -I pattern    Do not list files that match the given pattern.
  --noreport    Turn off file/directory count at end of tree listing.
  --charset X   Use charset X for terminal/HTML and indentation line output.
  --filelimit # Do not descend dirs with more than # files in them.
  --timefmt <f> Print and format time according to the format <f>.
  -o filename   Output to file instead of stdout.
  --du          Print directory sizes.
  --prune       Prune empty directories from the output.
  -------- File options ---------
  -q            Print non-printable characters as '?'.
  -N            Print non-printable characters as is.
  -Q            Quote filenames with double quotes.
  -p            Print the protections for each file.
  -u            Displays file owner or UID number.
  -g            Displays file group owner or GID number.
  -s            Print the size in bytes of each file.
  -h            Print the size in a more human readable way.
#NOTE: 只显示部分

常用操作:

生成目录树。

举例:

$ tree
.
├── blueprintexample
│   ├── blueprintexample.py
│   ├── simple_page
│   │   ├── __init__.py
│   │   ├── simple_page.py
│   │   └── templates
│   │   └── pages
│   │   ├── hello.html
│   │   ├── index.html
│   │   ├── layout.html
│   │   └── world.html
│   └── test_blueprintexample.py

显示文件大小:

$ tree -sh
.
├── [ 50M] 50M.file
├── [100M] bigfile
├── [1.5M] db_cms2.sql
├── [821K] db_cms.sql
├── [3.6K] index.html
├── [180M] interception_nh.mp4
├── [ 98K] t_news.sql
└── [2.9K] t_video_category.sql

显示目录

$ tree -d
.
└── uop
    ├── approval
    ├── auth
    ├── deploy_callback
    ├── deployment
    ├── disconf
    ├── dns
    ├── item_info
    ├── __pycache__
    ├── res_callback
    ├── resources
    ├── resource_view
    ├── static
    │   └── docs
    ├── user
    └── workbench

层级比较多的时候,显示指定层级的目录

$ tree -L 4
├── server.py
├── start.sh
├── uop
│   ├── static
│   │   └── docs
│   │       ├── api.json
│   │       ├── favicon-16x16.png
│   │       ├── favicon-32x32.png
│   │       ├── index.html
│   │       ├── oauth2-redirect.html
│   │       ├── swagger-ui-bundle.js
│   │       ├── swagger-ui-bundle.js.map
│   │       ├── swagger-ui.css
│   │       ├── swagger-ui.css.map
│   │       ├── swagger-ui.js
│   │       ├── swagger-ui.js.map
│   │       ├── swagger-ui-standalone-preset.js
│   │       └── swagger-ui-standalone-preset.js.map
│   ├── user
│   │   ├── errors.py

扩展阅读:
http://blog.csdn.net/beyondlpf/article/details/6922261

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容