Linux & Mac

1.下载tree lib

//mac
brew install tree
//centos
yum install tree
//ubuntu
apt-get install tree

用法

//显示所有文件
tree
//显示深度2层
tree -L 2

2. 命令find组合

find . -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g' > structure.txt

移除node_module

find . -print | grep -v "node" | sed -e 's;[^/]*/;|____;g;s;____|; |;g' > structure.txt

缺点: 不能打印深度选择,或者需要更高层次的语法编写。这里姑且先用着。够用了。

Windows

windows自带tree命令。默认只显示目录

//只显示目录
tree//显示文件
tree /f//输出到文件
tree /f > structure.txt

但,由于windows命令不熟悉,也不想花时间去学习windows的命令。那么可以装一个git shell或者推荐使用cmder。

Customization

手动写一个列表。先序遍历:

/*** 先序遍历 postorder traversal  先输出根节点,然后输出子节点* Created by Ryan Miao on 9/24/17.*/
public class PostorderTraversal {@Testpublic void testPostOrder() {String root = "/Users/ryan/workspace/learning/hexo-blog-src";int stop = 3;ArrayList<String> ignores = Lists.newArrayList(".git", ".deploy_git", "node_modules", ".DS_Store");printTree(root, stop, ignores);}private void printTree(String rootFile, int stop, List<String> ignores) {printTree(new File(rootFile), 0, stop, ignores, false, true);}private void printTree(File rootFile, int level, int stop, List<String> ignores, boolean isLastChild, boolean isParentLast) {String name = rootFile.getName();if (level > stop || ignores.stream().anyMatch(name::contains)) {return;}if (level == 0) {System.out.println(".");} else {prettyPrint(level, rootFile, isLastChild, isParentLast);}if (rootFile.isDirectory()) {File[] files = rootFile.listFiles();if (files != null) {int length = files.length;for (int i = 0; i < length; i++) {if (i == length - 1) {//printTree(files[i], level + 1, stop, ignores, true, isLastChild);} else {printTree(files[i], level + 1, stop, ignores, false, isLastChild);}}}}}private void prettyPrint(int level, File file, boolean isLastChild, boolean isParentLast) {StringBuilder sb = new StringBuilder();if (level != 1) {sb.append("│");}for (int i = 0; i < level - 2; i++) {if (isParentLast && i == level - 3) {sb.append("    ");break;}sb.append("   |");}if (level != 1) {sb.append("   ");}if (isLastChild) {sb.append("└──");} else {sb.append("├──");}sb.append(file.getName());System.out.println(sb.toString());}
}

目前有个bug,就是递归到深入之后,孙子无法得知祖父是不是最终叶子,因此虚线没有去掉。不过,简单能用还是可以的。
console output:

.
├──_config.yml
├──db.json
├──package-lock.json
├──package.json
├──public
│   ├──2017
│   |   ├──05
│   |   ├──06
│   |   ├──07
│   |   ├──08
│   |   └──09
│   ├──404.html
│   ├──about
│   |   └──index.html
│   ├──archives
│   |   ├──2017
│   |   ├──index.html
│   |   └──page
│   ├──baidusitemap.xml
│   ├──categories
│   |   ├──Cache
│   |   ├──Git
│   |   ├──Hexo
│   |   ├──index.html
│   |   ├──Java
│   |   ├──Java8
│   |   ├──Javascript
│   |   ├──Linux
│   |   ├──MySQL
│   |   ├──ReactJS
│   |   ├──redis
│   |   ├──Server
│   |   ├──Spring
│   |   ├──Tools
│   |   ├──思考
│   |   └──读书
│   ├──CNAME
│   ├──css
│   |   └──main.css
│   ├──gallery
│   |   └──index.html
│   ├──images
│   |   ├──algolia_logo.svg
│   |   ├──alipay.jpg
│   |   ├──avatar.gif
│   |   ├──avatar.jpeg
│   |   ├──bk.bmp
│   |   ├──bk.jpg
│   |   ├──bk.png
│   |   ├──bk2.jpg
│   |   ├──cc-by-nc-nd.svg
│   |   ├──cc-by-nc-sa.svg
│   |   ├──cc-by-nc.svg
│   |   ├──cc-by-nd.svg
│   |   ├──cc-by-sa.svg
│   |   ├──cc-by.svg
│   |   ├──cc-zero.svg
│   |   ├──loading.gif
│   |   ├──placeholder.gif
│   |   ├──quote-l.svg
│   |   ├──quote-r.svg
│   |   ├──searchicon.png
│   |   └──wechat.jpg
│   ├──index.html
│   ├──js
│   |   └──src
│   ├──lib
│   |   ├──algolia-instant-search
│   |   ├──canvas-nest
│   |   ├──canvas-ribbon
│   |   ├──fancybox
│   |   ├──fastclick
│   |   ├──font-awesome
│   |   ├──Han
│   |   ├──jquery
│   |   ├──jquery_lazyload
│   |   ├──pace
│   |   ├──three
│   |   ├──ua-parser-js
│   |   └──velocity
│   ├──links
│   |   └──index.html
│   ├──page
│   |   ├──2
│   |   └──3
│   ├──search.xml
│   ├──sitemap.xml
│   └──tags
│       ├──ArrayList
│       ├──banner
│       ├──Dropwizard
│       ├──EhCache
│       ├──Feign
│       ├──Git
│       ├──Hexo
│       ├──index.html
│       ├──Java
│       ├──Java8
│       ├──Javascript
│       ├──Lambda
│       ├──Linux
│       ├──Mac
│       ├──MySQL
│       ├──NodeJS
│       ├──ReactJS
│       ├──reading
│       ├──redis
│       ├──Server
│       ├──Spring
│       ├──SpringMVC
│       ├──team
│       ├──UTF-8
│       ├──vim
│       ├──Webpack
│       ├──Windows
│       └──码云
├──README.md
├──scaffolds
│   ├──draft.md
│   ├──page.md
│   └──post.md
├──source
│   ├──404.html
│   ├──_data
│   |   └──links.yml
│   ├──_posts
│   |   ├──banner-ascii-2-txt.md
│   |   ├──dropwizard-feign.md
│   |   ├──Ehcache3入门-Spring集成.md
│   |   ├──git-rebase.md
│   |   ├──hello-react-js.md
│   |   ├──hello-world.md
│   |   ├──hexo-github-oschina.md
│   |   ├──hexo-next-hypercomments.md
│   |   ├──hexo-next-shang.md
│   |   ├──http-server-static.md
│   |   ├──Java-ArrayList-remove.md
│   |   ├──java-utf8-iso-乱码根源.md
│   |   ├──java8-in-action-2.md
│   |   ├──java8-lambda.md
│   |   ├──js-cros.md
│   |   ├──mac-install-mysql.md
│   |   ├──mac-install-redis.md
│   |   ├──react-tutorial-1.md
│   |   ├──reading-schedule.md
│   |   ├──spring400.md
│   |   ├──switch-to-oschina.md
│   |   ├──team-first-chance.md
│   |   ├──tree.md
│   |   ├──vim.md
│   |   └──why-string-is-immutable.md
│   ├──about
│   |   └──index.md
│   ├──categories
│   |   └──index.md
│   ├──CNAME
│   ├──gallery
│   |   └──index.md
│   ├──images
│   |   ├──alipay.jpg
│   |   ├──avatar.jpeg
│   |   ├──bk.bmp
│   |   ├──bk.jpg
│   |   ├──bk.png
│   |   ├──bk2.jpg
│   |   └──wechat.jpg
│   ├──links
│   |   └──index.md
│   └──tags
│       └──index.md
├──themes
│   ├──landscape
│   |   ├──_config.yml
│   |   ├──Gruntfile.js
│   |   ├──languages
│   |   ├──layout
│   |   ├──LICENSE
│   |   ├──package.json
│   |   ├──README.md
│   |   ├──scripts
│   |   └──source
│   └──next
│       ├──.bowerrc
│       ├──.editorconfig
│       ├──.hound.yml
│       ├──.javascript_ignore
│       ├──.jshintrc
│       ├──.stylintrc
│       ├──.travis.yml
│       ├──_config.yml
│       ├──bower.json
│       ├──gulpfile.coffee
│       ├──languages
│       ├──layout
│       ├──LICENSE
│       ├──package.json
│       ├──README.cn.md
│       ├──README.md
│       ├──scripts
│       ├──source
│       └──test
└──thems-bak
│   └──next
│       ├──_config.yml
│       └──custom.styl

参考

mac 下的 tree 命令 终端展示你的目录树结构

命令行打印文件树列表: tree相关推荐

  1. 命令行打印文件树列表: tree 1

    Linux & Mac 1.下载tree lib //mac brew install tree //centos yum install tree //ubuntu apt-get inst ...

  2. linux显示文件开头部分内容,Linux 命令 - head: 打印文件的开头部分

    命令格式 head [OPTION]... [FILE]... 命令参数 -c, --bytes=[-]K 显示每个文件的前 K 字节内容. -n, --lines=[-]K 显示每个文件的前 K 行 ...

  3. Day07 红帽Linux —从命令行管理文件

    红帽Linux - 从命令行管理文件 文章目录 红帽Linux - 从命令行管理文件 一.目录文件夹内容及作用 练习题目 答案 二.路径定位和目录信息 路径定位 路径 切换目录 查看目录内容 ls指令 ...

  4. java打印文件树的代码

    输出的结构类似于linux下的tree命令如下: 原创不易,转载请注明出处:java打印文件树的代码 package com.zuidaima.file;import java.io.File; im ...

  5. Maven命令行查看依赖树

    Maven 是当前最普及的包管理工具,在我们的项目变大后会时不时的遇到需要解决依赖冲突的场景.这里介绍一种通过Maven中的插件,基于命令行实现依赖树查看的方法. 基本命令如下: mvn depend ...

  6. linux用cat命令创建一个文件,用cat在命令行创建文件

    我们常常使用cat命令来将某个文件的内容一口气打印出来查看,其实,cat命令还可以用来在命令行创建文件. cat在命令行创建文件与vi不同,只能单行编辑,换行之后就不能再编辑前面的行:与echo编辑多 ...

  7. 使用winzip命令行对文件打包压缩

    使用winzip命令行对文件打包压缩 ,通过程序和命令行对WinZip进行调用. 去http://www.winzip.com/downcl.htm  下载dos版的winzip,下载后直接安装,就会 ...

  8. 命令行修改文件文件夹访问权限 cacls, 修改hosts内容方法

    背景 日常使用Windows的过程中,hosts(C:\Windows\System32\drivers\etc)文件可能被一些程序串改,因此在网上找到禁止/允许修改hosts文件的bat脚本,但是在 ...

  9. 利用WinRAR命令行压缩文件或文件夹

    利用WinRAR命令行压缩文件或文件夹 2007-11-14 15:07 压缩文件夹winrar.exe a -ag -k -r -s -ibck c:/bak.rar c:/dat/ 压缩多个文件 ...

最新文章

  1. 单片机直接驱动段式液晶
  2. 计算机网络基础-目录
  3. 老牌语言依然强势,GO、Kotlin 等新语言为何不能破局?
  4. iOS tableview嵌套collectionview
  5. Home vs2013
  6. NetScaler Networking Deployment
  7. bigdecimal计算开n次方_随笔:HashMap中容量为什么是2的次方数?
  8. 怎么在不重启tomcat服务器的情况下更新修改过的后台代码,修改类不用重启Tomcat加载整个项目...
  9. 51单片机下的温控智能小风扇
  10. C 修改内存制作外挂
  11. windowsPE系统的制作
  12. 别人总结归纳很全的三方库
  13. Halcon入门(3)——回形针目标提取
  14. Sketch之初见BF
  15. java学生通讯录_简单实现Java通讯录系统
  16. Android开发艺术探索——第十四章:JNI和NDK编程
  17. 企业网络信息化建设解决方案
  18. sql依据单个字段去重_sql如何去重查询
  19. python画k线图_python自动获取行情数据,并画k线图
  20. 利用光猫IPTV通道实现双拨上网成功

热门文章

  1. 临床试验方案应包括哪些条目?
  2. 疾病相关数据查找,Our world in data使用指南
  3. 2021-11-13SystemStringBuliding
  4. 第21天学习Java的笔记-数学工具类Arrays,Math
  5. 第十天学习Java的笔记(数组)
  6. php nginx实现负载均衡,使用Nginx简单实现负载均衡
  7. html 如何用图片代替单选按钮,HTML中图像代替提交按钮
  8. python3.7 keras和tensorflow兼容_结果无法在Python中用Keras和TensorFlow重现
  9. python安装与开发环境搭建实验总结_python实验一:python环境配置
  10. 吴恩达深度学习笔记13-Course4-Week4【人脸识别和神经风格转换】