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

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 命令 终端展示你的目录树结构

转载于:https://www.cnblogs.com/woshimrf/p/tree.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/282922.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

java 二分法查找数组,Java二分法查找数组元素下标

package pers.ly.javase.algorithm;import java.util.Arrays;/*** 二分法查找* author: Lu Yang* date: 2019-01-23 10:50:37**/public class BinarySearch {public static void main(String[] args) {Integer[] arr {10,50,30,40,10,80,90,70,60,40,100,10};// 数组排序 ->…

ASP.NET Core MVC压缩样式、脚本及总是复制文件到输出目录

前言 在.NET Core之前对于压缩样式文件和脚本我们可能需要借助第三方工具来进行压缩&#xff0c;但在ASP.NET MVC Core中则无需借助第三方工具来完成&#xff0c;本节我们来看看ASP.NET Core MVC为我们提供了哪些方便。 自动压缩样式和脚本 当我们在测试环境中肯定不需要压缩脚…

京东订单自动评价方法

刚刚完成的一个京东自动订单脚本, 以后还要加入其它京东自动的脚本项目地址: https://github.com/mm333444/aox_jd_auto_script 京东自动完成脚本 目前只完成京东订单自动评价, 评价时会自动上传商品图片 一、安装 1. 程序依赖 python3.52. 安装配置 安装pipenv安装模块 pipenv…

matlab空间散点拟合曲线,matlab离散点拟合曲线

matlab曲线拟合与数值点标注实例_工程科技_专业资料。实例 1: 现已知两组...Matlab教程 曲线拟合工具箱 数学科学与技术学院 胡金燕 lionfr 曲线拟合定义 在实际工程应用和科学实践中,经常需要寻求 两个(或多个)变量间的关系,而......(p,x); %获得x点处对相应的y值 plot(x,y,r*…

redis下并发问题解决方案

http://effective.blog.51cto.com/8296150/1671743 现在的计算机大都是多核的cpu,意味着可以并行执行多个进程.如果这多个运行的进程对同一份数据进行读写操作,那么就有可能出现两个或者多个进程读到的都是老的数据,这种情况下,再进行写入操作之后就会有一些进程写入的数据被覆…

宜建立自主可控的车用芯片和操作系统技术体系

万物互联时代&#xff0c;操作系统的边界在不断突破&#xff0c;面向“人机物”融合的泛在计算场景&#xff0c;能够支撑分布式人机物协同应用的操作系统将是产业未来之光。操作系统在经过主机时代、PC互联时代、移动互联时代之后&#xff0c;来到万物互联时代&#xff0c;这恰…

Java 9进入第一轮问题修复阶段

Java 9功能特性正式完成&#xff0c;这意味着第一个问题修复阶段已经开始。HTTP/2客户端没有在截止日期前完成&#xff0c;现已降级为孵化器功能。由于现在的目标是在7月准备好可发布的Java 9&#xff0c;所以目前不太可能添加任何新的JEP。\\InfoQ此前的报道中提到&#xff0c…

django 用户管理(1)

编辑了前端的页面展示&#xff0c;用的bootstrap 用户登录 用户信息 用户编辑 创建用户 修改密码 转载于:https://blog.51cto.com/jacksoner/2133129

qiaoye.php,全自动无限生成关键词页面(黑帽SEO优化终极方法)

如果你是做黑帽SEO的&#xff0c;如果你还停留在用栏目、租域名、劫持等手段来做黑帽SEO优化&#xff0c;我可以肯定的告诉你&#xff0c;你做的再好&#xff0c;也赚不了多少。那么今天咱们要说的就是无限生成关键词页面用内容页来做黑帽SEO优化。这是我在演示的时候做的一个站…

AR Software

... 转载于:https://www.cnblogs.com/2008nmj/p/7264769.html

v1.0.25 新版发布及Smart Meetup重新开启丨SmartIDE

作者&#xff1a;徐磊文章首发地址&#xff1a;https://smartide.cn/zh/blog/2022-0892-sprint25/关于SmartIDESmartIDE是一群开发者为所有开发者开发的开源云原生IDE&#xff0c;我们的使命是“为开发者赋予云原生的超能力”&#xff01;使用SmartIDE你只需要学会一个简单的指…

线程安全的单例模式

面试的时候&#xff0c;常常会被问到这样一个问题&#xff1a;请您写出一个单例模式&#xff08;Singleton Pattern&#xff09;吧。好吧&#xff0c;写就写&#xff0c;这还不容易。顺手写一个&#xff1a; public final class EagerSingleton { private static EagerSi…

vue实现首屏加载等待动画 避免首次加载白屏尴尬

为什么80%的码农都做不了架构师&#xff1f;>>> 0 直接上效果图 1背景&#xff0c;用户体验良好一直是个重要的问题。 2怎么加到自己项目里面&#xff1f; 复制css html代码到自己的index.html即可 代码链接 源码地址 Vue学习前端群493671066&#xff0c;美女多多。…

java-回调机制详解

转&#xff1a;http://blog.csdn.net/llayjun/article/details/50454148 阅读目录 一、前言二、回调的含义和用途三、Java实现接口回调 四、Android中的接口回调五、参考资料一、前言 最近在看android fragment与Activity进行数据传递的部分&#xff0c;看到了接口回调的内容&a…

lfi读取php,php LFI读php文件源码以及直接post webshell

php LFI读php文件源码以及间接post 网站shell假如如下一个场景(&#xff11;) http://vulnerable/fileincl/example&#xff11;.php?pageintro.php(该php文件包孕LFI漏洞)(&#xff12;) 然而你不有中央能够upload你的网站shell代码(三) LFI只能读取到非php文件的源码(由于无…

根据请求上下文动态设置静态文件存储目录

前言上次&#xff0c;我们实现了根据 subpath 特定格式《动态设置静态文件存储目录》。例如&#xff1a;subpath静态文件路径/userAId/1.jpgc:\abc\userAId\1.jpg/userBId/1.jpgd:\xyz\123\userBId\1.jpg但是&#xff0c;如果 subpath 不能有这种特定格式&#xff0c;只能用通用…

BZOJ3019 : [Balkan2012]handsome

首先预处理出$f[i][j][k]$表示长度为$i$的序列&#xff0c;第一个位置是$j$&#xff0c;最后一个位置是$k$时合法的方案数。 从后往前枚举LCP以及那个位置应该改成什么。 用线段树维护区间内最左最右的已经确定的位置&#xff0c;以及区间内的合法方案数。 合并的时候只需要将左…

php smarty入门,smarty 快速入门

smarty 快速入门smarty定义:一个开源的模板引擎模板引擎是为了使用户界面与业务数据分离而产生的&#xff0c;它可以生成特定格式的文档&#xff0c;用于网站的模板引擎就会生成一个标准的HTML文档。功能将网站的数据和网站的界面实现分离(php和html代码)缓存页面下载www.smart…

ImageView的scaleType理解

2019独角兽企业重金招聘Python工程师标准>>> 1.android:scaleType“center” 保持原图的大小&#xff0c;显示在ImageView的中心。当原图的size大于ImageView的size时&#xff0c;多出来的部分被截掉。 2.android:scaleType“center_inside” 以原图正常显示为目的&…

第一章 引论

1、什么是多道程序设计&#xff1f; 即内存中同时运行多道独立程序&#xff0c;宏观上所有程序同时运行&#xff0c;微观上程序串行&#xff0c;多道程序轮流占用CPU&#xff0c;提高了资源利用率。 2、什么是SPOOLING&#xff1f;读者是否认为将来的高级个人计算机会把SPOOLIN…