生成目录结构树 tree

      我们在工作中经常会用到目录结构,比如在向客户提交产品资料的时候,需要一份清单来说明提交了哪些资料,资料多的时候往往需要一个一个来整理,下面介绍一种快速的方法;

一、mac系统

  1、推荐 brew 安装 tree

    brew install tree

xyz$ brew install tree
Warning: You are using OS X 10.12.
We do not provide support for this pre-release version.
You may encounter build failures or other breakages.
Please create pull-requests instead of filing issues.
==> Downloading http://mama.indstate.edu/users/ice/tree/src/tree-1.7.0.tgz
######################################################################## 100.0%
==> make prefix=/usr/local/Cellar/tree/1.7.0 MANDIR=/usr/local/Cellar/tree/1.7.0/share/man/ma
🍺  /usr/local/Cellar/tree/1.7.0: 7 files, 113.2K, built in 8 seconds
View Code

    然后 man tree 会显示tree命令的帮助  

    在资料目录下运行tree  即可看到效果;下边介绍几个常用的命令:

      -L level      Descend only level directories deep. 只显示到当前规定的level级别的文件夹结构

      -o filename   Output to file instead of stdout.   输出机构到指定的文件

      --help        Print usage and this help message and exit.  展示使用和帮助

    比如本例子中的list.txt, 即是  tree -L 1 -o list.txt  命令生成的,可以看到list.txt也被包含其中了;

macbook-pro:test xyz$ tree -L 1
.
├── list.txt
├── test0
├── test1
├── test2
├── test3
└── test4
View Code

    ==============

    pspsp:出现如下情况时:

macbook-pro:test xyz$ tree -L 3
sed: illegal option -- L
usage: sed script [-Ealn] [-i extension] [file ...]
       sed [-Ealn] [-i extension] [-e script] ... [-f script_file] ... [file ...]

  which tree 找到 tree命令所在目录:比如:/usr/local/bin/tree

      同2中,在.bash_profile添加 alias tree="/usr/local/bin/tree"即可

 

  2、使用find命令模拟出tree命令的效果

    在$home下的.bash_profile 文件中添加:

1 alias tree="find . -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'"

   然后记得编译使其生效:source .bash_profile

  

  参考:mac tree命令mac 终端中添加tree命令显示文件目录结构

二、windows系统

  参考:如何使用tree命令生成目录结构树

  win 的命令行下 进入资料所在文件目录

  tree /f > list.txt

    

    

posted @ 2017-10-27 15:00  半天的半天  阅读(4808)  评论(0编辑  收藏  举报