本操作使用場(chǎng)景:Mac OS 窑滞, Homebrew
1.安裝(tree)工具
brew install tree
2.Tree操作說明
安裝完成后良漱,可直接運(yùn)行:tree 毅弧,既可自動(dòng)生成當(dāng)前目錄文件下目錄結(jié)構(gòu)局义。
輸入 tree help 可查看tree項(xiàng)目可操作命令喜爷,具體命令結(jié)構(gòu)如下:
$ tree --help
usage: tree [-adfghilnpqrstuvxACDFNS] [-H baseHREF] [-T title ] [-L level [-R]]
[-P pattern] [-I pattern] [-o filename] [--version] [--help] [--inodes]
[--device] [--noreport] [--nolinks] [--dirsfirst] [--charset charset]
[--filelimit #] [<directory list>]
-a All files are listed(列出所有文件).
-d List directories only(只列出目錄).
-l Follow symbolic links like directories.(遵循象目錄這樣的符號(hào)鏈接)
-f Print the full path prefix for each file(打印每個(gè)文件的完整路徑前綴).
-i Don't print indentation lines()不要打印壓痕線.
-q Print non-printable characters as '?'.(將不可打印字符打印為'?'冗疮。)
-N Print non-printable characters as is.(按原樣打印不可打印字符)
-p Print the protections for each file.(打印每個(gè)文件的保護(hù))
-u Displays file owner or UID number(顯示文件所有者或UID號(hào)).
-g Displays file group owner or GID number.(顯示文件組所有者或GID編號(hào))
-s Print the size in bytes of each file.(打印每個(gè)文件的字節(jié)大小)
-h Print the size in a more human readable way.(以更容易被人閱讀的方式打印尺寸)
-D Print the date of last modification.(打印上次修改的日期)
-F Appends '/', '=', '*', or '|' as per ls -F.(根據(jù)ls -F添加'/'、'='檩帐、'*'或'|'术幔。)
-v Sort files alphanumerically by version.(按版本對(duì)文件進(jìn)行字母數(shù)字排序)
-r Sort files in reverse alphanumeric order.(按字母數(shù)字倒序排列文件。)
-t Sort files by last modification time.(按上次修改時(shí)間排序文件)
-x Stay on current filesystem only.(只保留當(dāng)前文件系統(tǒng))
-L level Descend only level directories deep.(只向下深入到級(jí)別目錄)
-A Print ANSI lines graphic indentation lines.(打印ANSI線圖形壓痕線)
-S Print with ASCII graphics indentation lines.(用ASCII圖形縮進(jìn)行打印)
-n Turn colorization off always (-C overrides).(始終關(guān)閉著色(-C覆蓋))
-C Turn colorization on always.(始終打開彩色化)
-P pattern List only those files that match the pattern given.(只列出與給定模式匹配的文件)
-I pattern Do not list files that match the given pattern.(不要列出與給定模式匹配的文件)
-H baseHREF Prints out HTML format with baseHREF as top directory.(打印出以baseHREF作為頂部目錄的HTML格式)
-T string Replace the default HTML title and H1 header with string.(用字符串替換默認(rèn)的HTML標(biāo)題和H1標(biāo)題)
-R Rerun tree when max dir level reached.(當(dāng)達(dá)到最大dir級(jí)別時(shí)重新運(yùn)行樹)
-o file Output to file instead of stdout.(輸出到文件而不是stdout湃密。)
--inodes Print inode number of each file.(打印每個(gè)文件的inode編號(hào))
--device Print device ID number to which each file belongs.(打印每個(gè)文件所屬的設(shè)備ID號(hào))
--noreport Turn off file/directory count at end of tree listing.(在樹列表末尾關(guān)閉文件/目錄計(jì)數(shù))
--nolinks Turn off hyperlinks in HTML output(關(guān)閉HTML輸出中的超鏈接).
--dirsfirst List directories before files.(在文件之前列出目錄)
--charset X Use charset X for HTML and indentation line output.(使用charset X作為HTML和縮進(jìn)行輸出)
--filelimit # Do not descend dirs with more than # files in them.(不要下載包含超過#文件的dirs)
3.常用方法舉例
3.1 指定遍歷層級(jí)
tree -L 2
("2" - 表示當(dāng)前文件夾下第幾級(jí)文件)
3.2 導(dǎo)出到指定文件 Readme.md
(*會(huì)覆蓋整個(gè)文本內(nèi)容)
tree -L 2 >README.md
3.2 過濾指定文件夾
tree -I "文件夾名"
如下過濾 node_modules
tree -I "node_modules"
過濾多文件夾
Tree -d -I "文件夾A|文件夾B|文件夾C"
tree -d -I "node_modules|weapp"
3.3 只顯示文件夾
tree -d
如下 過濾node_modules?只顯示文件夾
tree -d -I "node_modules"