Sử dụng lệnh “tree” liệt kê thư mục và file theo dạng cây trên Linux

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

2.1 List include all hidden 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/

1
2
Previous article[Ebook] IT Security Interviews Exposed Job – Secrets to Landing Your Next Information Security Job
Next article[Tech] Buổi chia sẻ/hội thảo “Chuẩn bảo mật thanh toán PCI DSS – Kinh nghiệm triển khai” – 25/3/2017
Bạn đang theo dõi website "https://cuongquach.com/" nơi lưu trữ những kiến thức tổng hợp và chia sẻ cá nhân về Quản Trị Hệ Thống Dịch Vụ & Mạng, được xây dựng lại dưới nền tảng kinh nghiệm của bản thân mình, Quách Chí Cường. Hy vọng bạn sẽ thích nơi này !