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 { @Test
public 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. Ubuntu使用命令行打印文件

    Ubuntu使用命令行打印文件 正文 环境: Ubuntu 16.04.3 LTS HP Deskjet InkAdvantage 4648 准备步骤 安装Common UNIX Printing S ...

  2. 在Linux下使用命令行打印文件

    近期需要将数学笔记打印出来复习,才发现Linux KDE环境下的默认PDF软件Okular根本无法将我在GoodNotes B5大小的页面写下的内容自适应地放大到A4纸上,只能以页面的原始尺寸打印.然 ...

  3. 分布式进阶(十) linux命令行下载文件以及常用工具:wget、Prozilla、MyGet、Linuxdown、Curl、Axel

    linux命令行下载文件以及常用工具:wget.Prozilla.MyGet.Linuxdown.Curl.Axel 本文介绍常用的几种命令行式的下载工具:wget.Prozilla.MyGet.Li ...

  4. Linux基础命令---lp打印文件

    lp lp指令用来打印文件,也可以修改存在的打印任务.使用该指令可以指定打印的页码.副本等. 此命令的适用范围:RedHat.RHEL.Ubuntu.CentOS.Fedora.openSUSE.SU ...

  5. Linux基础命令---lpr打印文件

    lpr lpr指令用来打印文件,如果没有指定文件名,那么从标准输入读取内容.CUPS提供了许多设置默认目标的方法.首先查询“LPDEST”和“PRINTER”环境变量.如果没有设置,则使用lpopti ...

  6. FileZilla命令行实现文件上传以及CreateProcess实现静默调用

    应用需求:         用户在选择渲染作业时面临两种情况:一是选择用户远程存储上的文件:二是选择本地文件系统中的文件进行渲染.由于渲染任务是在远程主机上进行的,实际进行渲染时源文件也是在ftp目录 ...

  7. Linux进程-命令行参数和环境列表

    命令行参数 在C中,main函数有很多的变种,比如 main(), int main(), int main(int argc, char *argv[]), int main(int argc, c ...

  8. Windows中通过命令行新建文件夹、新建文件,和一些常用命令

    新建文件 和Linux不太一样,Linux中的touch和vi命令创建新文件的方法都不能用了,在windows命令行下得用type nul>文件名.后缀名来创建: F:\study\vue\wo ...

  9. 使用SSH命令行传输文件到远程服务器

    以前一直在windows下用SSH Secure Shell连接远程服务器,它自带了一个可视化的文件传输工具,跟ftp差不多 但是它也存在一个缺陷,不支持编码的选择,遇到utf8就自动乱码了,另外ma ...

随机推荐

  1. Code Forces 698A Vacations

    题目描述 Vasya has nn days of vacations! So he decided to improve his IT skills and do sport. Vasya know ...

  2. Gitlab使用QQ企业邮箱发送邮件

    注册QQ企业邮箱 地址 https://exmail.qq.com/signupfree?refer=intro#signup/free 注册完成后解析 编辑/etc/gitlab/gitlab.rb ...

  3. QNJR-GROUP/EasyTransaction: 依赖于Spring的一个柔性事务实现,包含 TCC事务,补偿事务,基于消息的最终一致性事务,基于消息的最大努力交付事务交付QNJR-GROUP/EasyTransaction: 依赖于Spring的一个柔性事务实现,包含 TCC事务,补偿事务,基于消息的最终一致性事务,基于消息的最大努力交付事务交付

    QNJR-GROUP/EasyTransaction: 依赖于Spring的一个柔性事务实现,包含 TCC事务,补偿事务,基于消息的最终一致性事务,基于消息的最大努力交付事务交付 大规模SOA系统的分 ...

  4. spring-boot 速成(12) - 如何注入多个redis StringRedisTemplate

    默认情况下,spring-boot的redis自动配置,只能注册一个StringRedisTemplate实例,如果希望注入多个,比如:1个读写database 0,1个读写database 1 .. ...

  5. MDK5 and STM32Cube

    D:\Workspace\........\RTE\Device>STM32CubeMX.exe -s project.script -tpl_path C:\Keil5\ARM\Pack\Ke ...

  6. Answer Sheet - Both, Either & Neither

    http://www.usingenglish.com/quizzes/answers.php?quiz_id=44 This page displays the answers to the 'Bo ...

  7. ElasticSearch入门 :Windows下安装ElasticSearch

    这是ElasticSearch 2.4 版本系列的第一篇: ElasticSearch入门 第一篇:Windows下安装ElasticSearch ElasticSearch入门 第二篇:集群配置 E ...

  8. setInterval设置停止和循环

    原文链接:http://caibaojian.com/setinterval-times.html 需要知道已经经过了多少次或者说过多久就会停止 var timesRun = 0; var inter ...

  9. iOS内存管理 -讲的不错,角度独特

    ios的内存管理,包括对象的所有权与引用计数.自动释放.访问器方法与属性.一些会改变引用计数的特殊情况          ----- 对象所有权(ownership) 与引用计数 (retain co ...

  10. UITabBarController 详解之 hidesBottomBarWhenPushed的正确用法

    今天说的是在TabBar嵌套Nav时,进行Push的时候隐藏TabBar的问题. 之前项目也需要这么做,那时候iOS7还没出,也是各种搜罗,后来的解决方法是当push操作的时候自己隐藏Tabbar,p ...