命令行打印文件樹列表: 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.pswp.cn/news/282922.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/282922.shtml
英文地址,請注明出處:http://en.pswp.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…