Contents
How to use “tree” command to list directory with tree structure on Linux
Tree command is a application in UNIX/Linux OS that can help you list all files/directories at specific path directory with the format view of tree style. This command can scan recursively sub directory to find all files for listing. It’s very help ful for you, trust me.
Installing and using command tree command on Linux
1. Installing application command ‘tree’
Default, tree
is not installed in Linux/UNIX so you can have it with below steps.
+ RHEL/CentOS
# yum install tree
+ Ubuntu/Debian
# sudo apt-get install tree
2. Syntax command
Syntax
tree /path/to/directory tree [options] tree [options] /path/to/directory
2.1 Basic default mode command
# tree /etc/ /etc/ ├── adjtime ├── aliases ├── aliases.db ├── alternatives │ ├── ld -> /usr/bin/ld.bfd │ ├── libnssckbi.so.x86_64 -> /usr/lib64/pkcs11/p11-kit-trust.so │ ├── 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 ├── anacrontab ├── asound.conf ├── audisp │ ├── audispd.conf │ └── plugins.d │ ├── af_unix.conf │ └── syslog.conf ├── audit │ ├── auditd.conf │ ├── audit.rules │ ├── audit.rules.prev │ └── rules.d │ └── audit.rules ├── avahi │ └── avahi-autoipd.action ├── bash_completion.d │ ├── git │ ├── iprutils │ ├── pip │ ├── yum │ └── yummain.py -> yum .... ... ├── yum.conf └── yum.repos.d ├── CentOS-Base.repo ├── CentOS-CR.repo ├── CentOS-Debuginfo.repo ├── CentOS-fasttrack.repo ├── CentOS-Media.repo ├── CentOS-Sources.repo ├── CentOS-Vault.repo ├── dell-omsa-repository.repo ├── epel.repo └── epel-testing.repo 198 directories, 987 files
In default mode of ‘tree‘, it will not list information of hidden files (files begin with dot ‘.‘ of name file). So you can use option ‘-a’ to see that.
# tree -a /etc/
2.2 Limit the number sub-directory will be listed (scanned)
You want to limit the number sub-directory that ‘tree’ will scan information, you can use option ‘-L <number>‘.
# tree -L 2 /etc/
2.3 Just list directory, no files
# tree -d
2.4 Manual
Find more information about this command ‘tree‘ on Linux, use command ‘manual‘.
# manual tree
Now you know additional command like ‘tree‘ to help you list files/directories on server at a specific directory path with beautiful style view is ‘tree‘. Thank you !
Nguồn: https://cuongquach.com/