使用 tree 命令格式化输出目录结构

来源:互联网 发布:java实现三级菜单栏 编辑:程序博客网 时间:2024/04/29 02:14

今天在写一个 Markdown 文件的时候需要将一个目录的结构表示出来,于是找了找有没有相关命令,找到一个叫做 tree 的命令,Windows 和 Linux 都有这个命令。


Windows 10

我是在 Windows 10 上用的,不过根据 这篇文章 应该在 Windows 7 和 8 上也是可以用的。用法如下:

tree [Drive:[[Path] [/F] [/A]

其中

  • /F 表示不仅输出文件夹,也输出文件名。默认是只输出文件夹的名字。
  • /A 表示使用另一种方式来绘制目录树。

例如:

仅列出目录

tree D:\MasterFiles\MachineLearning\TensorFlow\TensorFlow-Examples\MyCode\cifar10-TensorFlow-tensorboard

仅列出目录


另一种方式输出

tree D:\MasterFiles\MachineLearning\TensorFlow\TensorFlow-Examples\MyCode\cifar10-TensorFlow-tensorboard /A

另一种方式输出


列出目录及文件

tree D:\MasterFiles\MachineLearning\TensorFlow\TensorFlow-Examples\MyCode\cifar10-TensorFlow-tensorboard /F

列出目录及文件


Linux

由于我现在用的是 Windows 10,所以就先暂时用 Windows 10 自带的 Ubuntu 子系统测试了,回头再用真正的 Ubuntu 试试。关于如何使用 Windows 10 自带的 Ubuntu 子系统我就不多说了,大家直接百度就好,教程很多。

列出目录及文件

tree cifar10-TensorFlow-tensorboard

列出目录及文件


只列出目录

tree cifar10-TensorFlow-tensorboard -d

只列出目录

更详细的参数设置可以使用 man tree 查看,如果输入 tree 提示没有安装,那么可以使用 sudo apt-get install tree 来安装该命令。


END

1 0
原创粉丝点击