Linux/Ubuntu tree 命令以樹形結構顯示文件夾目錄結構


1、安裝命令工具

sudo apt-get -y install tree

2、可以查看關於tree命令的幫助信息

$ tree --help
usage: tree [-adfghilnpqrstuvxACDFNS] [-H baseHREF] [-T title ] [-L level [-R]]
        [-P pattern] [-I pattern] [-o filename] [--version] [--help] [--inodes]
        [--device] [--noreport] [--nolinks] [--dirsfirst] [--charset charset]
        [--filelimit #] [<directory list>]
  -a            All files are listed.
  -d            List directories only.
  -l            Follow symbolic links like directories.
  -f            Print the full path prefix for each file.
  -i            Don't print indentation lines.
  -q            Print non-printable characters as '?'.
  -N            Print non-printable characters as is.
  -p            Print the protections for each file.
  -u            Displays file owner or UID number.
  -g            Displays file group owner or GID number.
  -s            Print the size in bytes of each file.
  -h            Print the size in a more human readable way.
  -D            Print the date of last modification.
  -F            Appends '/', '=', '*', or '|' as per ls -F.
  -v            Sort files alphanumerically by version.
  -r            Sort files in reverse alphanumeric order.
  -t            Sort files by last modification time.
  -x            Stay on current filesystem only.
  -L level      Descend only level directories deep.

3、使用方法(常用)

(1) 顯示當前目錄的樹形結構

jianbao@jianbao-pc:/www/軟件開發$ tree 
.
├── PPT
│   └── PHP性能監控與優化.pptx
├── 電子書
│   ├── Linux.環境C程序設計.徐誠.掃描版.pdf
│   └── UNIX環境高級編程(中文第三版)_掃描版.pdf
├── 視頻
│   └── PHP_C擴展
│       ├── PHP擴展開發教程.mp4
│       ├── swoole第三節第4部分.mp4
│       ├── swoole視頻教程第3節 swoole服務器的進程_線程模型.mp4
│       └── 其他
│           ├── swoole-chat第二節第二部分.mp4
│           ├── swoole-chat第二節第三部分.mp4
└── 手冊
    └── php_enhanced_zh.chm

(2) 只查看當前第一級的目錄和文件

$ tree -L 1

(3) 只查看當前第二級的目錄和文件

$ tree -L 2

(4) 只查看當前第N級的目錄和文件

$ tree -L N

(5) 把目錄結構信息保存到文本中

$ tree -L 2 > /home/php-note.com/tree.txt


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM