tree
檔案與目錄
用法
tree -L 2 [path]把目錄結構畫成縮排的樹;macOS 和精簡的 Linux 映像檔裡預設沒有,得先安裝。
常用選項
| 選項 | 含義 |
|---|---|
| -L | Limit the depth to N levels |
| -a | Include hidden files |
| -d | Directories only |
| -I | Skip names matching a pattern |
| -f | Print the full path of each entry |
| -h | Show readable sizes |
範例
tree -L 2Two levels deep, so the output stays readable.
tree -I 'node_modules|.git'Skips the noisy directories.
tree -d -L 1Just the top-level folders.
搬移、刪除和尋找。有些命令不會再問一次,所以順手加 -i 是在救自己。
怎麼看
- 方括號 [ ] 表示這部分可以不寫。
- 省略號 … 表示可以寫多個。
- 選項區分大小寫——有些命令裡 -r 和 -R 不是一回事。
常見問題
Q. tree 是做什麼的?
把目錄結構畫成縮排的樹;macOS 和精簡的 Linux 映像檔裡預設沒有,得先安裝。
Q. 怎麼寫?
tree -L 2 [path] —— 方括號表示可以省略的部分。
Q. 值得記的選項有幾個?
這裡列了 6 個,完整列表在 man tree。這條命令屬於檔案與目錄。
相關命令
man 手冊: man tree