功能:树状结构输出目录和文件

安装

Mac
brew install tree

Linux
apt-get install tree

参数

输出指定目录下所有的目录和文件

显示出隐藏的文件

.env
-a 显示.开头的隐藏文件,但不显示 . 和 ..

  1. tree -a bootstrap
  2. bootstrap
  3. └── cache
  4. └── .env

只列出目录

-d

  1. tree -d bootstrap
  2. bootstrap
  3. └── cache

指定的目录递归层级

-L n level

  1. tree -L 1 bootstrap
  2. bootstrap
  3. ├── app.php
  4. └── cache

显示文件大小

-s 字节格式显示
-h 以人类可读的大小输出
—du 子目录大小包含了所有文件

  1. tree -h -du bootstrap
  2. bootstrap
  3. ├── [1.6K] app.php
  4. └── [ 16K] cache
  5. ├── [1.7K] packages.php
  6. └── [ 14K] services.php
  7. tree -h bootstrap
  8. bootstrap
  9. ├── [1.6K] app.php
  10. └── [ 160] cache
  11. ├── [1.7K] packages.php
  12. └── [ 14K] services.php
  13. tree -s bootstrap
  14. bootstrap
  15. ├── [ 1620] app.php
  16. └── [ 160] cache
  17. ├── [ 1757] packages.php
  18. └── [ 14692] services.php

显示目录前缀

-f

  1. tree -f bootstrp
  2. bootstrap
  3. ├── bootstrap/app.php
  4. └── bootstrap/cache
  5. ├── bootstrap/cache/packages.php
  6. └── bootstrap/cache/services.php

正则过滤

-P “正则”

  1. tree -P "*s.php" bootstrp
  2. bootstrap
  3. └── bootstrap/cache
  4. ├── bootstrap/cache/packages.php
  5. └── bootstrap/cache/services.php

输出到文件
-o

  1. tree -o file.txt path
  2. or
  3. tree path >> file.txt