西数超哥博客
运维经验教程分享

Linux系统通过tree命令打印指定N层级目录结构或文件

21运维原创,转载请注明文章。

我们都知道,linux环境下边了解查看目录层级结构是通过tree命令进行查看的。很多时候我们需要指定查看具体的层级目录结构,就不能单纯使用tree查看,尤其小文件多的时候,显示起来看的头都大,我们需要查看指定的层级。
默认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参数,可以更直观的查看。

转载请注明:西数超哥博客www.ysidc.top» Linux系统通过tree命令打印指定N层级目录结构或文件

https://www.ysidc.top 西数超哥博客,数据库,西数超哥,虚拟主机,域名注册,域名,云服务器,云主机,云建站,ysidc.top

赞(0)
声明:本站发布的内容(图片、视频和文字)以原创、转载和分享网络内容为主,若涉及侵权请及时告知,将会在第一时间删除。本站原创内容未经允许不得转载:西数超哥博客 » Linux系统通过tree命令打印指定N层级目录结构或文件