生活随笔
收集整理的這篇文章主要介紹了
tree
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
tree 參數選項:
-a:顯示所有文件,包括隱藏文件。
-d:只顯示目錄。
-f:顯示每個文件的全路徑。
-i:不顯示樹枝,常與-f參數配合使用。
-L level:遍歷目錄的最大層數,level為大于0的正整數。
-F:在執行文件,目錄,Socket,符號連接,管道名稱等不同類型文件的結尾,各自加上"*","/","@","|"號,類似ls命令的-F選項。
范例. 不帶參數
[root@testdb62 ~]# tree /tmp
/tmp
├── aaa.log
├── a.log
├── import_mysql_data.sh
├── systemd-private-0b4f7a702deb460eaee9b4daf2de2651-chronyd.service-nKWU9N
│ └── tmp
└── wordpress.zip
2 directories, 4 files
范例. 帶 -a 參數顯示包括隱藏文件的所有文件。
[root@testdb62 ~]# tree -a /tmp
/tmp
├── aaa.log
├── a.log
├── .font-unix
├── .ICE-unix
├── import_mysql_data.sh
├── systemd-private-0b4f7a702deb460eaee9b4daf2de2651-chronyd.service-nKWU9N
│ └── tmp
├── .Test-unix
├── wordpress.zip
├── .X11-unix
└── .XIM-unix
7 directories, 4 files
范例. 只列出根目錄下第一層目錄的結構( -L 功能)
-L 參數后接數字表示要查看目錄的層數,不帶 -L 選項默認顯示所有的層數。
[root@testdb62 ~]# tree -L 1 /data
/data
├── applogs
├── backup
├── backup2windows
├── clickhouse
├── code
├── docker_backup
├── docker_data
├── elasticsearch
├── hadoop
├── hbase
├── liquibase_sql
├── mongodb
├── mysql
├── mysql_3307
├── mysql_3308
├── mysqlbak
├── pgsql_data
├── redis
├── restore
├── xxl_job
├── zibo_binlog
└── zookeeper
22 directories, 0 files
范例. 只顯示所有的目錄(-d功能)
[root@testdb62 ~]# tree -d /data/mysql
/data/mysql
├── basedata
├── db_1
├── db_2
├── db_3306
├── jumpserver
├── mysql
├── nacos_dev
├── otter
├── performance_schema
├── scott
└── sys
11 directories
范例. -f 選項和 -i 選項的使用
-f 選項可顯示完整的路徑名稱,使用 -i 選項則不顯示樹枝部分。
1.顯示內容的完整路徑
[root@testdb62 ~]# tree -L 1 -f /boot/
/boot
├── /boot/config-3.10.0-1062.el7.x86_64
├── /boot/efi
├── /boot/grub
├── /boot/grub2
├── /boot/initramfs-0-rescue-304ba91566574244a4ed6752152ec067.img
├── /boot/initramfs-3.10.0-1062.el7.x86_64.img
├── /boot/symvers-3.10.0-1062.el7.x86_64.gz
├── /boot/System.map-3.10.0-1062.el7.x86_64
├── /boot/vmlinuz-0-rescue-304ba91566574244a4ed6752152ec067
└── /boot/vmlinuz-3.10.0-1062.el7.x86_64
3 directories, 7 files
2. -i 不顯示樹枝,當需要獲取所有文件的完整路徑時,這個命令很好用
[root@testdb62 ~]# tree -L 1 -fi /boot/
/boot
/boot/config-3.10.0-1062.el7.x86_64
/boot/efi
/boot/grub
/boot/grub2
/boot/initramfs-0-rescue-304ba91566574244a4ed6752152ec067.img
/boot/initramfs-3.10.0-1062.el7.x86_64.img
/boot/symvers-3.10.0-1062.el7.x86_64.gz
/boot/System.map-3.10.0-1062.el7.x86_64
/boot/vmlinuz-0-rescue-304ba91566574244a4ed6752152ec067
/boot/vmlinuz-3.10.0-1062.el7.x86_64
3 directories, 7 files
范例.使用tree命令區分目錄和文件的方法
1.使用 -F 參數會在目錄后面添加 “/”,方便區分目錄
[root@testdb62 ~]# tree -L 1 -F /boot/
/boot/
├── config-3.10.0-1062.el7.x86_64
├── efi/
├── grub/
├── grub2/
├── initramfs-0-rescue-304ba91566574244a4ed6752152ec067.img
├── initramfs-3.10.0-1062.el7.x86_64.img
├── symvers-3.10.0-1062.el7.x86_64.gz
├── System.map-3.10.0-1062.el7.x86_64
├── vmlinuz-0-rescue-304ba91566574244a4ed6752152ec067*
└── vmlinuz-3.10.0-1062.el7.x86_64*
3 directories, 7 files
2. 過濾以斜線結尾的所有內容
[root@testdb62 ~]# tree -L 1 -F /boot/ | grep /$
/boot/
├── efi/
├── grub/
├── grub2/
3. 使用 -d 參數只顯示目錄樹,這樣可輕松過濾內容中的目錄
[root@testdb62 ~]# tree -L 1 -d /boot/
/boot/
├── efi
├── grub
└── grub2
3 directories
總結
以上是生活随笔為你收集整理的tree的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。