我們在工作中經常會用到目錄結構,比如在向客戶提交產品資料的時候,需要一份清單來說明提交了哪些資料,資料多的時候往往需要一個一個來整理,下面介紹一種快速的方法;
一、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
然后 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
==============
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系統
win 的命令行下 進入資料所在文件目錄
tree /f > list.txt