你也想要生成这个目录树层结构吗?,按下面操作即可:

  1. ├── build
  2. ├── config
  3. ├── docs
  4. └── static
  5. ├── css
  6. └── js
  7. ├── src
  8. ├── assets
  9. ├── components
  10. ├── store
  11. └── modules
  12. └── views
  13. ├── book
  14. └── movie
  15. └── static

1. mac 下使用 brew包管理工具安装 tree

  1. brew install tree

2. 安装成功后,直接在终端使用,使用 —help 查看帮助信息

  1. tree --help

看到如下功能

  1. tree --help 10:06:14
  2. usage: tree [-acdfghilnpqrstuvxACDFJQNSUX] [-H baseHREF] [-T title ]
  3. [-L level [-R]] [-P pattern] [-I pattern] [-o filename] [--version]
  4. [--help] [--inodes] [--device] [--noreport] [--nolinks] [--dirsfirst]
  5. [--charset charset] [--filelimit[=]#] [--si] [--timefmt[=]<f>]
  6. [--sort[=]<name>] [--matchdirs] [--ignore-case] [--] [<directory list>]
  7. ------- Listing options -------
  8. -a All files are listed.
  9. -d List directories only.
  10. -l Follow symbolic links like directories.
  11. -f Print the full path prefix for each file.
  12. -x Stay on current filesystem only.
  13. -L level Descend only level directories deep.
  14. -R Rerun tree when max dir level reached.
  15. -P pattern List only those files that match the pattern given.
  16. -I pattern Do not list files that match the given pattern.
  17. --ignore-case Ignore case when pattern matching.
  18. --matchdirs Include directory names in -P pattern matching.
  19. --noreport Turn off file/directory count at end of tree listing.
  20. --charset X Use charset X for terminal/HTML and indentation line output.
  21. --filelimit # Do not descend dirs with more than # files in them.
  22. --timefmt <f> Print and format time according to the format <f>.
  23. -o filename Output to file instead of stdout.
  24. -------- File options ---------
  25. -q Print non-printable characters as '?'.
  26. -N Print non-printable characters as is.
  27. -Q Quote filenames with double quotes.
  28. -p Print the protections for each file.
  29. -u Displays file owner or UID number.
  30. -g Displays file group owner or GID number.
  31. -s Print the size in bytes of each file.
  32. -h Print the size in a more human readable way.
  33. --si Like -h, but use in SI units (powers of 1000).
  34. -D Print the date of last modification or (-c) status change.
  35. -F Appends '/', '=', '*', '@', '|' or '>' as per ls -F.
  36. --inodes Print inode number of each file.
  37. --device Print device ID number to which each file belongs.
  38. ------- Sorting options -------
  39. -v Sort files alphanumerically by version.
  40. -t Sort files by last modification time.
  41. -c Sort files by last status change time.
  42. -U Leave files unsorted.
  43. -r Reverse the order of the sort.
  44. --dirsfirst List directories before files (-U disables).
  45. --sort X Select sort: name,version,size,mtime,ctime.
  46. ------- Graphics options ------
  47. -i Don't print indentation lines.
  48. -A Print ANSI lines graphic indentation lines.
  49. -S Print with CP437 (console) graphics indentation lines.
  50. -n Turn colorization off always (-C overrides).
  51. -C Turn colorization on always.
  52. ------- XML/HTML/JSON options -------
  53. -X Prints out an XML representation of the tree.
  54. -J Prints out an JSON representation of the tree.
  55. -H baseHREF Prints out HTML format with baseHREF as top directory.
  56. -T string Replace the default HTML title and H1 header with string.
  57. --nolinks Turn off hyperlinks in HTML output.
  58. ---- Miscellaneous options ----
  59. --version Print version and exit.
  60. --help Print usage and this help message and exit.
  61. -- Options processing terminator.

3. 输出你的树层目录结构

  1. cd 目标文件夹路径
  2. 然后 tree 一下,会将该层级下所有文件都遍历了输出,不管层级多深

  3. 4. 常用技巧

  4. 我们可以在目录遍历时使用 -L 参数指定遍历层级

    1. tree -L 2
  5. 如果你想把一个目录的结构树导出到文件 Readme.md ,可以这样操作

    1. tree -L 2 >README.md //然后我们看下当前目录下的 README.md 文件
  6. 只显示文件夹;

    1. tree -d
  7. 显示项目的层级,n表示层级数。例:显示项目三层结构,tree -l 3;

    1. tree -L n
  8. tree -I pattern 用于过滤不想要显示的文件或者文件夹。比如要过滤项目中的node_modules文件夹;

    1. tree -I node_modules

    Ref

    mac 下的 tree 命令 终端展示你的目录树结构
    转载至简书
    作者:Jacob_LJ
    链接:https://www.jianshu.com/p/9411d60950bf