用 tree 以树状结构查看目录

tree 以缩进层级显示目录结构,支持限制深度、显示隐藏文件和大小——很多人忘了它需要额外安装。

Linux目录列表tree 目录树低风险
运行 `tree -L 2` 显示两层目录树,加 `-a` 可包含隐藏文件。

01命令

命令
$ tree -L 2 -a

02作用说明

其他常用参数:`-d` 只显示目录,`-h` 配合 `-s` 显示人类可读大小,`-I 'node_modules|.git'` 排除无关目录,`-o 文件.txt` 把清单存为文档。不加深度限制时,在大目录上运行 tree 会刷爆终端,所以记得先加 -L。没装 tree 的话,`ls -R` 是退而求其次的选择。

03风险

风险低风险
使用条件tree installed (apt install tree / dnf install tree); not preinstalled on many distros

04撤销

✓无需撤销——该命令不会改变持久状态。

05来源

  • tree(1) - Linux manual page
    Ubuntu Manpages · technical · 2026-09-17
    依据: tree lists the contents of directories in a tree-like format; -L limits the depth of display and -a includes hidden files.

最后验证: 2026-09-17 · 分类: 文件与文件夹