tree命令:文件目录结构以树形显示
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了tree命令:文件目录结构以树形显示相关的知识,希望对你有一定的参考价值。
参考技术A tree 命令可以使文件目录以树形结构显示,非常适合于给别人介绍我们的文件目录的组成框架,而且该命令使用适当的参数可以将命令结果输出到指定路径下的指定文件中保存。
注: 此处以centos 7系统为例,在centos 7系统中默认是没有tree这个命令的,需要安装,用下面的命令就可以安装tree这个命令工具
安装完成后使用 tree --help 命令可以查看tree命令的使用方法
linux 用树形命令tree 显示文件目录结构及处理CRT显示乱码问题
本经验均在CentOS release 6.7 (Final)下操作: 用ls 命令查看目录/var显示: # ls /var/ account crash db games local log nis preserve spool yp cache cvs empty lib lock mail opt run tmp 为了更直观的显示文件目录,我们用tree命令来显示:
# yum install tree Loaded plugins: fastestmirror, security Setting up Install Process base | 3.7 kB 00:00 base/primary_db | 4.7 MB 02:22 extras | 3.4 kB 00:00 extras/primary_db | 37 kB 00:00 updates | 3.4 kB 00:00 updates/primary_db | 89 kB 00:01 Resolving Dependencies --> Running transaction check ---> Package tree.x86_64 0:1.5.3-3.el6 will be installed --> Finished Dependency Resolution Dependencies Resolved =============================================================================== Package Arch Version Repository Size =============================================================================== Installing: tree x86_64 1.5.3-3.el6 base 36 k Transaction Summary =============================================================================== Install 1 Package(s) Total download size: 36 k Installed size: 65 k Is this ok [y/N]: y Downloading Packages: tree-1.5.3-3.el6.x86_64.rpm | 36 kB 00:00 warning: rpmts_HdrFromFdno: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6 Importing GPG key 0xC105B9DE: Userid : CentOS-6 Key (CentOS 6 Official Signing Key) <[email protected]> Package: centos-release-6-7.el6.centos.12.3.x86_64 (@anaconda-CentOS-201508042137.x86_64/6.7) From : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6 Is this ok [y/N]: y Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Installing : tree-1.5.3-3.el6.x86_64 1/1 Verifying : tree-1.5.3-3.el6.x86_64 1/1 Installed: tree.x86_64 0:1.5.3-3.el6 Complete!
tree命令安装完毕!
显示/var目录的一级目录和文件:
# tree -L 1 /var /var a”a”a” account a”a”a” cache a”a”a” crash a”a”a” cvs a”a”a” db a”a”a” empty a”a”a” games a”a”a” lib a”a”a” local a”a”a” lock a”a”a” log a”a”a” mail -> spool/mail a”a”a” nis a”a”a” opt a”a”a” preserve a”a”a” run a”a”a” spool a”a”a” tmp a””a”a” yp
19 directories, 0 files
显示乱码,产生乱码的原因就是:当前用户的环境LANG变量与crt的字符编码没有保持一致。
Linux的字符集查看:
# echo $LANG en_US.UTF-8
将CRT的字符集设置UTF-8即可 :
显示/var目录的一级目录和文件:正常
# tree -L 1 /var /var ├── account ├── cache ├── crash ├── cvs ├── db ├── empty ├── games ├── lib ├── local ├── lock ├── log ├── mail -> spool/mail ├── nis ├── opt ├── preserve ├── run ├── spool ├── tmp └── yp 19 directories, 0 files
tree的系统帮助:
# tree --help usage: tree [-adfghilnpqrstuvxACDFNS] [-H baseHREF] [-T title ] [-L level [-R]] [-P pattern] [-I pattern] [-o filename] [--version] [--help] [--inodes] [--device] [--noreport] [--nolinks] [--dirsfirst] [--charset charset] [--filelimit #] [<directory list>] -a All files are listed. -d List directories only. -l Follow symbolic links like directories. -f Print the full path prefix for each file. -i Don‘t print indentation lines. -q Print non-printable characters as ‘?‘. -N Print non-printable characters as is. -p Print the protections for each file. -u Displays file owner or UID number. -g Displays file group owner or GID number. -s Print the size in bytes of each file. -h Print the size in a more human readable way. -D Print the date of last modification. -F Appends ‘/‘, ‘=‘, ‘*‘, or ‘|‘ as per ls -F. -v Sort files alphanumerically by version. -r Sort files in reverse alphanumeric order. -t Sort files by last modification time. -x Stay on current filesystem only. -L level Descend only level directories deep. -A Print ANSI lines graphic indentation lines. -S Print with ASCII graphics indentation lines. -n Turn colorization off always (-C overrides). -C Turn colorization on always. -P pattern List only those files that match the pattern given. -I pattern Do not list files that match the given pattern. -H baseHREF Prints out HTML format with baseHREF as top directory. -T string Replace the default HTML title and H1 header with string. -R Rerun tree when max dir level reached. -o file Output to file instead of stdout. --inodes Print inode number of each file. --device Print device ID number to which each file belongs. --noreport Turn off file/directory count at end of tree listing. --nolinks Turn off hyperlinks in HTML output. --dirsfirst List directories before files. --charset X Use charset X for HTML and indentation line output. --filelimit # Do not descend dirs with more than # files in them.
本文出自 “evil” 博客,请务必保留此出处http://evil001.blog.51cto.com/911643/1784146
以上是关于tree命令:文件目录结构以树形显示的主要内容,如果未能解决你的问题,请参考以下文章
Linux/Ubuntu tree 命令以树形结构显示文件夹目录结构