生成目錄結構樹 tree

      咱們在工做中常常會用到目錄結構,好比在向客戶提交產品資料的時候,須要一份清單來講明提交了哪些資料,資料多的時候每每須要一個一個來整理,下面介紹一種快速的方法;html

1、mac系統

  一、推薦 brew 安裝 treewindows

    brew install treebash

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命令的幫助  ide

    在資料目錄下運行tree  便可看到效果;下邊介紹幾個經常使用的命令:post

      -L level      Descend only level directories deep. 只顯示到當前規定的level級別的文件夾結構ui

      -o filename   Output to file instead of stdout.   輸出機構到指定的文件this

      --help        Print usage and this help message and exit.  展現使用和幫助url

    好比本例子中的list.txt, 便是  tree -L 1 -o list.txt  命令生成的,能夠看到list.txt也被包含其中了;spa

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"便可

 

  二、使用find命令模擬出tree命令的效果

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

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

   而後記得編譯使其生效:source .bash_profile

  

  參考:mac tree命令mac 終端中添加tree命令顯示文件目錄結構

2、windows系統

  參考:如何使用tree命令生成目錄結構樹

  win 的命令行下 進入資料所在文件目錄

  tree /f > list.txt

相關文章
相關標籤/搜索