Linux系統通過tree命令列印指定N層級目錄結構或檔案

來源:互聯網
上載者:User

ee查看,尤其小檔案多的時候,顯示起來看的頭都大,我們需要查看指定的層級。
預設tree命令是沒有安裝的,需要單獨進行yum 或apt-get安裝。tree參數的詳細可以通過tree –help進行查看,下邊簡單瞭解下常用的幾個參數:
-C:對tree顯示的進行顏色顯示,便於查看。
-d: 只顯示目錄。
-L:顯示層級數量,關鍵參數。

比如我們查看/etc下邊的三層檔案和目錄:

[root@drlb etc]# tree  -L 3
.
├── adjtime
├── aliases
├── aliases.db
├── alternatives
│   ├── bin-iptables-xml.x86_64 -> /bin/iptables-xml-1.4.7
│   ├── ip6tables.x86_64 -> /sbin/ip6tables-1.4.7
│   ├── iptables.x86_64 -> /sbin/iptables-1.4.7
│   ├── libip4tc000.x86_64 -> /lib64/libip4tc.so.0.0.0-1.4.7
│   ├── libip4tc0.x86_64 -> /lib64/libip4tc.so.0-1.4.7
│   ├── libip6tc000.x86_64 -> /lib64/libip6tc.so.0.0.0-1.4.7
│   ├── libip6tc0.x86_64 -> /lib64/libip6tc.so.0-1.4.7
│   ├── libipq000.x86_64 -> /lib64/libipq.so.0.0.0-1.4.7
│   ├── libipq0.x86_64 -> /lib64/libipq.so.0-1.4.7
│   ├── libiptc000.x86_64 -> /lib64/libiptc.so.0.0.0-1.4.7
│   ├── libiptc0.x86_64 -> /lib64/libiptc.so.0-1.4.7
│   ├── libnssckbi.so.x86_64 -> /usr/lib64/nss/libnssckbi.so
│   ├── libxtables400.x86_64 -> /lib64/libxtables.so.4.0.0-1.4.7
│   ├── libxtables4.x86_64 -> /lib64/libxtables.so.4-1.4.7
│   ├── man-ip6tables-restore.x86_64 -> /usr/share/man/man8/ip6tables-restore-1.4.7.8.gz
│   ├── man-ip6tables-save.x86_64 -> /usr/share/man/man8/ip6tables-save-1.4.7.8.gz
│   ├── man-ip6tables.x86_64 -> /usr/share/man/man8/ip6tables-1.4.7.8.gz
│   ├── man-iptables-restore.x86_64 -> /usr/share/man/man8/iptables-restore-1.4.7.8.gz
│   ├── man-iptables-save.x86_64 -> /usr/share/man/man8/iptables-save-1.4.7.8.gz
│   ├── man-iptables.x86_64 -> /usr/share/man/man8/iptables-1.4.7.8.gz
│   ├── man-iptables-xml.x86_64 -> /usr/share/man/man8/iptables-xml-1.4.7.8.gz
│   ├── mta -> /usr/sbin/sendmail.postfix
│   ├── mta-aliasesman -> /usr/share/man/man5/aliases.postfix.5.gz
│   ├── mta-mailq -> /usr/bin/mailq.postfix
│   ├── mta-mailqman -> /usr/share/man/man1/mailq.postfix.1.gz
│   ├── mta-newaliases -> /usr/bin/newaliases.postfix
│   ├── mta-newaliasesman -> /usr/share/man/man1/newaliases.postfix.1.gz
│   ├── mta-pam -> /etc/pam.d/smtp.postfix
│   ├── mta-rmail -> /usr/bin/rmail.postfix
│   ├── mta-sendmail -> /usr/lib/sendmail.postfix
│   ├── mta-sendmailman -> /usr/share/man/man1/sendmail.postfix.1.gz
│   ├── sbin-ip6tables-multi.x86_64 -> /sbin/ip6tables-multi-1.4.7
│   ├── sbin-ip6tables-restore.x86_64 -> /sbin/ip6tables-restore-1.4.7
│   ├── sbin-ip6tables-save.x86_64 -> /sbin/ip6tables-save-1.4.7
│   ├── sbin-iptables-multi.x86_64 -> /sbin/iptables-multi-1.4.7
│   ├── sbin-iptables-restore.x86_64 -> /sbin/iptables-restore-1.4.7
│   └── sbin-iptables-save.x86_64 -> /sbin/iptables-save-1.4.7
├── anacrontab
├── audisp
│   ├── audispd.conf
│   └── plugins.d
│       ├── af_unix.conf
│       └── syslog.conf
├── audit
│   ├── auditd.conf
│   └── audit.rules
├── bash_completion.d
│   ├── gdbus-bash-completion.sh
│   ├── gsettings-bash-completion.sh
│   ├── salt.bash
│   ├── yum.bash
│   └── yum-utils.bash
├── bashrc
├── blkid
│   └── blkid.tab
├── centos-release
├── chkconfig.d
├── cron.d
│   ├── 0hourly
│   ├── raid-check
│   └── vnstat
├── cron.daily
│   └── logrotate
├── cron.deny
├── cron.hourly
│   └── 0anacron
├── cron.monthly
├── crontab
├── cron.weekly
├── crypttab
├── csh.cshrc
├── csh.login
├── dbus-1
│   └── system.d
│       └── Upstart.conf
├── default
│   ├── nss
│   └── useradd
├── depmod.d
│   └── dist.conf
├── dhcp
│   └── dhclient.d
├── DIR_COLORS
├── DIR_COLORS.256color
├── DIR_COLORS.lightbgcolor
├── dracut.conf
├── dracut.conf.d
├── environment
├── ethers
├── exports
├── favicon.png -> /usr/share/icons/hicolor/16x16/apps/system-logo-icon.png
├── filesystems
├── fonts
│   ├── conf.avail
│   │   ├── 10-autohint.conf
│   │   ├── 10-no-sub-pixel.conf
│   │   ├── 10-sub-pixel-bgr.conf
│   │   ├── 10-sub-pixel-rgb.conf
│   │   ├── 10-sub-pixel-vbgr.conf
│   │   ├── 10-sub-pixel-vrgb.conf
│   │   ├── 10-unhinted.conf
│   │   ├── 20-fix-globaladvance.conf
│   │   ├── 20-unhint-small-vera.conf
│   │   ├── 25-unhint-nonlatin.conf
│   │   ├── 30-metric-aliases.conf
│   │   ├── 30-urw-aliases.conf
│   │   ├── 40-nonlatin.conf
│   │   ├── 45-latin.conf
│   │   ├── 49-sansserif.conf
│   │   ├── 50-user.conf
│   │   ├── 51-local.conf
│   │   ├── 60-latin.conf
│   │   ├── 65-fonts-persian.conf
│   │   ├── 65-khmer.conf
│   │   ├── 65-nonlatin.conf
│   │   ├── 69-unifont.conf
│   │   ├── 70-no-bitmaps.conf
│   │   ├── 70-yes-bitmaps.conf
│   │   ├── 80-delicious.conf
│   │   └── 90-synthetic.conf
│   ├── conf.d
│   │   ├── 20-fix-globaladvance.conf -> ../conf.avail/20-fix-globaladvance.conf
│   │   ├── 20-unhint-small-vera.conf -> ../conf.avail/20-unhint-small-vera.conf
│   │   ├── 25-no-bitmap-dist.conf
│   │   ├── 25-unhint-nonlatin.conf -> ../conf.avail/25-unhint-nonlatin.conf
│   │   ├── 30-metric-aliases.conf -> ../conf.avail/30-metric-aliases.conf
│   │   ├── 30-urw-aliases.conf -> ../conf.avail/30-urw-aliases.conf
│   │   ├── 40-nonlatin.conf -> ../conf.avail/40-nonlatin.conf
│   │   ├── 45-latin.conf -> ../conf.avail/45-latin.conf
│   │   ├── 49-sansserif.conf -> ../conf.avail/49-sansserif.conf
│   │   ├── 50-user.conf -> ../conf.avail/50-user.conf
│   │   ├── 51-local.conf -> ../conf.avail/51-local.conf
│   │   ├── 60-latin.conf -> ../conf.avail/60-latin.conf
│   │   ├── 65-fonts-persian.conf -> ../conf.avail/65-fonts-persian.conf
│   │   ├── 65-nonlatin.conf -> ../conf.avail/65-nonlatin.conf
│   │   ├── 69-unifont.conf -> ../conf.avail/69-unifont.conf
│   │   ├── 80-delicious.conf -> ../conf.avail/80-delicious.conf
│   │   ├── 90-synthetic.conf -> ../conf.avail/90-synthetic.conf
│   │   └── README
│   ├── fonts.conf
│   └── fonts.dtd
├── fstab
├── gai.conf
├── gcrypt
├── gnupg
├── group
├── group-
├── grub.conf -> ../boot/grub/grub.conf
├── gshadow
├── gshadow-
├── host.conf
├── hosts
├── hosts.allow
├── hosts.deny
├── init
│   ├── control-alt-delete.conf
│   ├── init-system-dbus.conf
│   ├── kexec-disable.conf
│   ├── plymouth-shutdown.conf
│   ├── prefdm.conf
│   ├── quit-plymouth.conf
│   ├── rc.conf
│   ├── rcS.conf
│   ├── rcS-emergency.conf
│   ├── rcS-sulogin.conf
│   ├── serial.conf
│   ├── splash-manager.conf
│   ├── start-ttys.conf
│   └── tty.conf
├── init.d -> rc.d/init.d
├── inittab
├── inputrc
├── iproute2
│   ├── ematch_map
│   ├── rt_dsfield
│   ├── rt_protos
│   ├── rt_realms
│   ├── rt_scopes
│   └── rt_tables
├── iscsi
│   ├── initiatorname.iscsi
│   └── iscsid.conf
├── issue
├── issue.net
├── keepalived
│   └── keepalived.conf
├── krb5.conf
 
如果只顯示目錄,我們可以使用tree -d -L 3

[root@drlb etc]# tree  -d  -L 3
.
├── alternatives
├── audisp
│   └── plugins.d
├── audit
├── bash_completion.d
├── blkid
├── chkconfig.d
├── cron.d
├── cron.daily
├── cron.hourly
├── cron.monthly
├── cron.weekly
├── dbus-1
│   └── system.d
├── default
├── depmod.d
├── dhcp
│   └── dhclient.d
├── dracut.conf.d
├── fonts
│   ├── conf.avail
│   └── conf.d
├── gcrypt
├── gnupg
├── init
├── init.d -> rc.d/init.d
├── iproute2
├── iscsi
├── keepalived
 
如果加上顏色顯示,可以加上-C參數,可以更直觀的查看。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.