相信很多使用過Linux的用戶都用過tree
命令,它可以像windows的文件管理器一樣清楚明了的顯示目錄結構。mac 下使用 brew包管理工具安裝 tree
前提:安裝了homebrew(安裝指令
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
)
brew install tree
正常的顯示開始安裝(這才是開始下載)
Downloading https://homebrew.bintray.com/bottles/tree-1.8.0.mojave.bottle.tar.gz
如果報錯
Error: The following directories are not writable by your user: /usr/local/sbin You should change the ownership of these directories to your user. sudo chown -R $(whoami) /usr/local/sbin And make sure that your user has write permission. chmod u+w /usr/local/sbin
要先按照上面的指令執行
chmod u+w /usr/local/sbin sudo chown -R $(whoami) /usr/local/sbin # 這里會讓輸入登錄密碼,輸入即可
安裝成功后,直接在終端使用, 使用 --help 查看幫助信息
tree --help
在目錄遍歷時使用 -L 參數指定遍歷層級
tree -L 1 #-L 1 指只顯示一級目錄
把一個目錄的結構樹導出到文件 Readme.md
tree -L 2 >README.md
如果要查看的目錄包含中文,用:
tree -N